Re: Delay Routine: Fully-portable C89 if possible

CBFalconer wrote:
David Brown wrote:
... snip ...
Secondly, I was suggesting that if you want portable code, you have
to use size-specific integer types. Using <stdint.h> is an easy
way to get that - otherwise, a common format header file that is
adapted for the compiler/target in question is a useful method. It doesn't really matter whether you use "uint32_t" from <stdint.h>,
or have a "typedef unsigned long int uint32_t" in a common header
file - nor does it matter if you give the type your own name. But
it *does* matter that you have such types available in your code.

I disagree. "unsigned long" is guaranteed to have at least 32
bits. Similarly "unsigned int" is guaranteed at least 16 bits, as
is "unsigned short". "unsigned char" is at least 8 bits. These
types are ALWAYS available, but the various 'uint32_t' etc. types
are not. Even if present, they are only present on a C99 compiler
system. Why abandon portability unnecessarily?

As you say, an "unsigned long int" is guaranteed (by any strictly compliant compiler) to have *at least* 32 bits. But nowhere is it specified to have *at most* 32 bits. Thus "unsigned long int" is useless if I want *exactly* 32 bits. That is why the <stdint.h> types were defined, and that is why they are important if you want portable code that works on a wide range of targets (at least, for architectures that can support 8, 16 and 32-bit data - targets with 36 bit cpus, for example, will always be problematic for portable code). When you are using compilers without <stdint.h>, you need to write your own header with suitable typedefs - then you can keep your source code portable.

Relevant Pages

  • Re: Header Files and Interfaces Yet Again
    ... compiler is not allowed to read them. ... illustrate the difference of header file and fake header. ... fake headers can not serve as sufficient information to the ... > something but it appears to me the Standard Library is not designed ...
  • Re: Cpp Considered Harmful
    ... >> I will observe that many Java IDEs do this rather successfully. ... > Look, if a tool author is willing to fully parse the underlying language, ... > compiler version. ... mentions a header file is in the C compatability appendix. ...
  • Re: Name conflict
    ... The changed 3rd party header file now uses a typedef to define an ... Is there a way to tell the compiler to use my #define of XYZ over the ... enumeration constant XYZ? ...
  • Re: Header Files and Interfaces Yet Again
    ... >> The point that I hope to get across is that header files need to provide ... a compiler has to know about them at compile time. ... But he actually uses what you call a fake header. ... differences between Java and C++: In Java all obects appear to be handles. ...
  • Re: managing header files
    ... The chances that every source file needs every other source file's header is approximately nil. ... When a system gets to hundreds of source files, this can reduce the compilation time significantly because the compiler reads fewer files. ... while in the .h files the external declarations showed no arguments. ...