Style guides and portability

D'Arcy J.M. Cain darcy at druid.uucp
Wed Jan 16 04:02:44 AEST 1991


In article <10608 at hydra.Helsinki.FI> Lars Wirzenius writes:
>In article <1991Jan13.182655.17672 at athena.mit.edu> scs at adam.mit.edu writes:
>>P.S. The answer to "How do you print something declared with
>>`int32 bigint;' ?" is that you have to abandon printf in favor of
>>something you define, like "print32".  I find this awkward, and
>Is there any problem in using 
>	printf("%ld", (long) bigint)
>other than that it's clumsy?

I'm currently writing code that has this problem.  I have some types
such as:

typedef long TASK_ID;
typedef int HANDLE;
etc...

where I may want to change the types in the future.  I solved the printf
problem by doing the following:

#define f_TASK_ID "ld"
#define f_HANDLE "d"
...
printf("Current task is %5" f_TASK_ID " for handle %" f_HANDLE "\n", t, h);

Now if I change the type I just change the corresponding define and
re-compile.  Of course it is even clumsier but I think it makes the
changes easier to handle.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |



More information about the Comp.lang.c mailing list