Gautam said:
Can any one tell me what are the types in C which are non
portable/which make C non-portable
is it
a)structures, or
b)unions, or
3)bit-fields, or
are all of them , i am confused
C isn't binary compatible. For instance float x = 0.1f will produce
different bit patterns on machines with different floating-point
architectures, and since 0.1 cannot be represented exactly in most formsts
may be slightly under on some machines and slightly over on others.
Similarly int, longs, and even chars may have different numbers of bits, and
might not even have twos complement representation for negative numbers.
When you get to structures, unions and bitfields, not only may the
individual members differ, but the padding and layout in memory may differ.
This is because some machines like values to be aligned on word boundaries.
For practical purposes, what you need to know is that fwrite() ing a
structure to disk will produce an binary image that can be fread() only by a
program produced by the same compiler (the same goes of course for sending
bytes down a socket). You also need to know that C programs won't
necessarily produce the same bit-for-bit result, even though they will still
be correct, if you use floating point. If you use pointers incorrectly as
scalar values, or you exceed the minimum size of an integer type, you will
also get different results on different platforms.