Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overcome "u_int8_t vs uint8_t" issue efficiently

Tags:

c

types

I am trying to build a package (libnet) in Solaris and I found that in Solaris there are no u_xxx_t but uxxx_t defined in sys/types.h

I had 2 questions:

1-Shouldn't autotools take care of this for me?

2-I guess I'm not the first one facing this (although google was little help) is there a standard/eficient/correct/quick way of overcoming this?

like image 829
B-K Avatar asked Jun 23 '10 16:06

B-K


3 Answers

The most reasonable way of overcoming tis is to stick with the standard spelling of the type names (even if that standard is a "future" one for the implementation you are using). C99 introduced a standard nomenclature for such type names and in C99 it is uint8_t. So, even if you are using a C89/90 compiler I'd suggest you use uint8_t in your code. If on some platform it is unavailable or spelled differently, you simply introduce a platform-specific typedef name that "converts" the spelling

typedef u_int8_t uint8_t;

For this to work you'll need a header file that is included into every translation unit. Normally, each project has one created specifically for solving issues like this one.

like image 137
AnT Avatar answered Nov 14 '22 10:11

AnT


The typename uint8_t is standard, so I'm not sure where you found u_int8_t.

This is simple enough that you can do it a fast, dumb way with perl (or sed, if you must), and fix any minor problems that it causes by hand:

perl -pi.orig -e "s/\bu_(\w+_t)\b/u$1/g" *.c

(This will save the original, unmodified files with the .orig suffix.)

like image 36
JSBձոգչ Avatar answered Nov 14 '22 10:11

JSBձոգչ


  1. No
  2. Use conditional preprocessor directives i.e. #define u_xxx_t uxxx_t or typedef wrapped in a #ifdef block, i.e. typedef u_xxx_t uxxx_t
like image 1
Adrian Regan Avatar answered Nov 14 '22 11:11

Adrian Regan