[En-Nut-Discussion] Do we realy need "include/net/errno.h"
duane ellis
ethernut at duaneellis.com
Mon Feb 16 22:11:35 CET 2009
Ole Reinhardt> do we realy need include/net/errno.h?
Harrald> avr-libc 1.6.4 and earlier as well as ICCAVR provide just
[basically - different compilers have different things... agh.... cross
compile builds are painful]
I've had to deal with this before, one *COULD* use ./configure
[shudder]. However, there is a simple trick that solves this *nicely* it
is as follows, and *many* non-unix hacks can easily understand and
follow it:
============================
Create a new "header" directory, call it NUT.
Applications have a choice:
option1: #include <stdio.h>
In the OPTION 1 case - it is not portable.
It works, and everybody is happy - life goes on.
**OR**
option2: #include <nut/stdio.h>
Option #2, solves portability issues.
For example: #include <nut/stdint.h>
Here's the advantage, OPTION #2 - is now "safe" - and cross platform, in
effect, <nut/stdint.h> becomes a wrapper that fixes all problems with
*THAT* compilers version of *THAT* header file.
you also don't have to play games with INCLUDE search path order... and
stuff like that.
The example <Nut/stdint.h> might read as follows:
===============
#ifndef NUT_STDINT_H
#define NUT_STDINT_H
#if defined(__GNU_GCC_MAJOR > 4 )
// all versions of GCC after 4.0 have stdint.h
#include <stdint.h>
#define NUT_STDINT_DONE 1
#endif
// the defines here are contrived to show the example - they are not
valid names
#if defined( __MS_VISUAL_STUDIO )
// visual studio is brain dead, it does not have stdint.
// use our fixers
#if __X86_32_BIT
#include <nut/stdint32_bit_helpers.h>
#endif
#if __X86_64BIT
#inlcude <nut/stdint64_bit_helpers.h>
#endif
#define NUT_STDINT_DONE 1
#endif
#if !defined(NUT_STDINT_DONE)
#error "Sorry STDINT is not setup for this compiler yet"
#endif
#endif // NUTSTDINT_H
===============
In a *PERFECT*WORLD* - it might read like this instead:
#ifndef NUT_STDIO_H
#define NUT_STDIO_H
// we live in a perfect world
#include <stdio.h>
#endif
===============
The trick here is this, if you need a "standard header file" - ie:
ERRNO, or STDINT, or whatever... you include it, via the "NUT" *wrapper*
version - which - *WILL* include the proper one eventually.
BUT - it may also contain all the required #ifdefs and other wackyness
to make it very portable.
-Duane.
More information about the En-Nut-Discussion
mailing list