Karl,
Your compiler is not 'broken'-any decent C book you may be using
should have mentioned that the size of an int is implementation dependent.
DOS/Windoze defines an int as a short int(2 bytes), whereas most flavors of
Unix define an int as a long int, which is 4 bytes. One of the uses of
sizeof() is to allow for variations like this across platforms, eg using
malloc/calloc/realloc() routines using sizeof(). Note that other data types
are not nescessarily the same across platforms either..
At 06:17 AM 7/5/98 -0600, Karl F. Larsen wrote:
> I am learning to write C and yesterday tried to write a program
>that used sizeof() and it is broken in my version of compiler. No matter
>what kind of variable, the Linux sizeof() returns 4. I went back to my old
>Borland DOS compiler and it works there.
>
> Please write this simple program on your Linux and see what you
>get:
>
>/* checks the function sizeof() */
>#include <stdio.h>
>int main(void)
>{
> printf("The size of an integer is %d bytes.\n", sizeof(int));
> return 0;
>}
>
> This prints 4 in Linux and 2 (which is correct) using Borland C++.
>
>Best wishes
>
> - Karl F. Larsen, 3310 East Street, Las Cruces,NM (505) 524-3303 -
>
>
>
|============================================================================|
| Scott Wegener | Email: [EMAIL PROTECTED] |
| Programmer Analyst |==========================================|
| Alphatronix | URL: http://members.tripod.com/~wegster |
| Research Triangle Park, NC | |
|============================================================================|
| There can be no greater Hell that that known by those who have been forced |
| to program in COBOL. |
|============================================================================|