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);
}