C++ problem

for everything else
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: C++ problem

Post by rnixon »

Ok Tod, thats a big raise. I have to fold. I'm not that good with templates.

Ron, a too think a signed short should be a signed 16-bit number, but I have heard that compilers optimized to 32-bits play some games, but I have not seen that myself.

I'm running 2.4 rc2 like Tod, and I don't see the same issue. As a test, does any behavior change if you cast the short to a float in your function call:

Debug("X - XatRest = ", (float) temp);
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: C++ problem

Post by tod »

The optimized issue is a good thought, try turning down the optimization level down to 1 or 0 (the default is usually 2). See if the behavior changes. I know in one version of the compiler a long long time ago I had troubles with -O2 and the volatile keyword.
Ron Neal
Posts: 17
Joined: Tue May 05, 2009 1:20 pm

Re: C++ problem

Post by Ron Neal »

Since I converted all of the short variables to int the problem has gone away. If I convert them back I will try it and let you know. I did clean up my debug routine and other references that called sprintf or siprintf, thanks for the advice.

void Debug(char* Msg, float ValueToShow){

char Str[100];
sprintf(Str, "<A>%s%.6f</A><INFO>ShowDebugButton</INFO>", Msg, ValueToShow);
SendUDPstr(Str, WinMachineAddr);
DebugStepBit = false;
while (DebugStepBit == false) OSTimeDly(2);//Remember OSTimeDly needs to be here so that
}

The last time I had to deal with complier bug was with an assembly language complier for Intels 8096 family. I pulled a few hairs out figuring that one out. At least I could inspect the actual output file and determine what it should be. It was VERY time consuming though.

Ron
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: C++ problem

Post by Ridgeglider »

In your exploration of short vs int, if you are wondering how many bytes and the range of values that can be stored in various C types, the following app dumps out info about the size of many of the standard C variable types as implemented on NB. It uses the standard files limits.h and float.h to determine the output.

Code: Select all

#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <NetworkDebug.h>



#include <limits.h>			// to explore max and min of various number formats



#include <C:\Nburn\gcc-m68k\lib\gcc\m68k-elf\4.2.1\include\float.h>
							// to explore max and min of floating number formats
							// Note: the 4.2.1 part of the path above may need
							// updating as NB system is Rev'd upwards.

extern "C" {
void UserMain(void * pd);
}


// Declaration for a function defined BELOW UserMain.
void ShowLimits(void);

const char * AppName="5282-Limits";

void UserMain(void * pd) {
    InitializeStack();

// Get IP Addr:
    const char *DeviceName = "NetBurner5282";
	pDHCPOfferName = DeviceName; // Host name for DNS

    if (EthernetIP == 0) {
    	iprintf("Trying DHCP...");
		if (DHCP_OK == GetDHCPAddress()) {
			iprintf("Successful\r\n");
		} else {
			iprintf("Failed\r\n");
		}
    }

	iprintf("\r\nAssigned IP: ");
	ShowIP(EthernetIP);
	iprintf("\r\n");

// Continue standard inits:
    OSChangePrio(MAIN_PRIO);
    EnableAutoUpdate();
    StartHTTP();
    EnableTaskMonitor();

    #ifndef _DEBUG
    EnableSmartTraps();
    #endif

    #ifdef _DEBUG
    InitializeNetworkGDB_and_Wait();
    #endif

// Done with inits, start the application:
    iprintf("Application started: %s\n", AppName);
    ShowLimits();

    while (1) {
        OSTimeDly(20);
    }
}


void ShowLimits(void) {
	iprintf("\r\n");
    iprintf("          Number TYPE :#Bytes: [             MinVal,      "
    		"        MaxVal ]\n");
 	iprintf("=============================================================="
 	"==============\n");
//====chars, BOOL, BOOLEAN, & BYTE==============================================
    iprintf("                 char : (%ld) : [%20d, %20d]\n",
       		sizeof(char),          CHAR_MIN,    CHAR_MAX  );
    iprintf("          signed char : (%ld) : [%20d, %20d]\n",
    		sizeof(signed char),   SCHAR_MIN,   SCHAR_MAX  );
    iprintf("        unsigned char : (%ld) : [%20hu, %20hu]\n",
    		sizeof(unsigned char), 0,           UCHAR_MAX  );
    iprintf("   unsigned char=BOOL : (%ld) : [%20hu, %20hu]\n",
    		sizeof(BOOL),          0,           UCHAR_MAX  );
    iprintf("unsigned char=BOOLEAN : (%ld) : [%20hu, %20hu]\n",
    		sizeof(BOOLEAN),       0,           UCHAR_MAX  );
    iprintf("   unsigned char=BYTE : (%ld) : [%20hu, %20hu]\n\n",
    		sizeof(BYTE),          0,           UCHAR_MAX  );

//====short & WORD==============================================================
    iprintf("                short : (%ld) : [%20d, %20d]\n",
    		sizeof(short),         SHRT_MIN, SHRT_MAX   );
    iprintf("         signed short : (%ld) : [%20d, %20d]\n",
    		sizeof(signed short),  SHRT_MIN, SHRT_MAX   );
    iprintf("   signed short=SHORT : (%ld) : [%20d, %20d]\n",
    		sizeof(SHORT),         SHRT_MIN, SHRT_MAX   );
    iprintf("       unsigned short : (%ld) : [%20hu, %20hu]\n",
    	   sizeof(unsigned short), 0,        USHRT_MAX  );
    iprintf("  unsigned short=WORD : (%ld) : [%20hu, %20hu]\n\n",
    	   sizeof(WORD),           0,        USHRT_MAX  );

//====int=======================================================================
    iprintf("                  int : (%ld) : [%20d, %20d]\n",
    		sizeof(int),          INT_MIN,   INT_MAX);
    iprintf("           signed int : (%ld) : [%20d, %20d]\n",
    	    sizeof(signed int),   INT_MIN,   INT_MAX);
	iprintf("         unsigned int : (%ld) : [%20u, %20u]\n\n",
    	    sizeof(unsigned int), 0,        UINT_MAX);

//====LONGS, DWORD==============================================================
    iprintf("                 long : (%ld) : [%20ld, %20ld]\n",
    		sizeof(long),          LONG_MIN, LONG_MAX  );
    iprintf("          signed long : (%ld) : [%20ld, %20ld]\n",
    		sizeof(signed long),   LONG_MIN, LONG_MAX );
    iprintf("     signed long=LONG : (%ld) : [%20ld, %20ld]\n",
    		sizeof(LONG),          LONG_MIN, LONG_MAX );
 	iprintf("        unsigned long : (%ld) : [%20u, %20lu]\n",
    		sizeof(unsigned long), 0,        ULONG_MAX  );
 	iprintf("  unsigned long=DWORD : (%ld) : [%20u, %20lu]\n\n",
    		sizeof(DWORD),         0,        ULONG_MAX  );

//====long longs================================================================
	iprintf("            long long : (%ld) : [%20lld, %20lld]\n",
    		sizeof(long long),          LONG_LONG_MIN, LONG_LONG_MAX  );
	iprintf("     signed long long : (%ld) : [%20lld, %20lld]\n",
    		sizeof(signed long long),   LONG_LONG_MIN, LONG_LONG_MAX );
	iprintf("   unsigned long long : (%ld) : [%20u, %20llu]\n",
    		sizeof(unsigned long long), 0,             ULONG_LONG_MAX  );

//====float & double============================================================
    printf("\n radix: %d\n", FLT_RADIX);
    printf(" float:  (%ld) : %d radix digits: ",
    	   sizeof(float), FLT_MANT_DIG);
    printf("[%15g, %20g]\n",   FLT_MIN, FLT_MAX   );

    printf("double:  (%ld) : %d radix digits: ",
    	   sizeof(double), DBL_MANT_DIG);
    printf("[%15g, %20g]\n\n",     DBL_MIN, DBL_MAX  );


    iprintf("Application done: %s\n", AppName);
}
Muneera123
Posts: 1
Joined: Fri Jun 01, 2018 2:58 am

Re: C++ problem

Post by Muneera123 »

c++ is medium and low programming language it can understand high level programming......in c++ does not supports automatic garbage collection feature this is one of the main problem compare to the other language like java....
it is less security compare to java why because java use reference only but coming to c++ it uses both references and pointer that feature is more safe in java ....
in c++ there no feature that why c++ is unsafe this is one more problem..........
Post Reply