C Type Sizes (ANSI C) (Any Platform)


ANSI C provides a SizeOF operator that allows you to see what byte size is being assigned to primitive types on different computers and operating systems.

This can be very useful for people working with embedded systems as it allows you to see what sizes are in use, you can then account for this in your code. It is always helpful to know what types sizes are in use to avoid errors.

The way the sizeOF operator works is to pass the byte size into an integer that can then be printed out for the user.

int c = sizeof(int);

This file will display the size of the follow types in bytes.

char

short

int

long

float

double

long double


This is a very easy way of finding out the capabilities of system

I have attached a video of how to compile this file.

Windows users will need to install a ‘C’ Compiler if they do not have one.

Unix users should have the GCC compiler installed as default.


To Compile this file open your command line environment/terminal/console.

Unzip and place main.c on your desktop


Change your present working directory to your Desktop e.g. cd Desktop

Then

gcc -o programname main.c


Where 'programname' represents whatever you want to call the program.

That will create a file called type sizes

This file can be run by typing ./typesize



Download Here!


© Jonathan Field 2011