From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,9ae5fbc502f16fef X-Google-Attributes: gid1164f8,public From: mogul@pa.dec.com (Jeffrey Mogul) Subject: Re: Compiler flags of dubious utility. Date: 1995/12/15 Message-ID: <4aqnhp$dpn@usenet.pa.dec.com>#1/1 X-Deja-AN: 121838147 references: <4akv6t$14i@topaz.sensor.com> <4akvcr$16q@topaz.sensor.com> organization: DEC Western Research newsgroups: comp.sys.dec In article <4akvcr$16q@topaz.sensor.com> ron@topaz.sensor.com (Ron Natalie) writes: > #include > main() { > fprintf(stdout, "Hello World\n"); > } > >Then compiling with the -xtaso_short and linking with -taso causes >a non-functioning executable to be generated. Your program was >just a little too trivial. Actually, I'm not sure if "-xtaso_short" is of much utility by itself. However, the 32-bit compiler support is actually pretty good, if you understand how to use it. It's the documentation that is weak. In order to use 32-bit pointers successfully, you usually need to do a tiny bit of work to make sure that pointers exchanged with the outside world are properly declared. Note that this does not apply to parameters, since the compiler promotes all 32-bit values to become 64-bit values. So the problem with the program is not that FILE *stdout is only 32 bits wide, but rather that it points to a FILE that contains pointer fields, and although the library thinks these pointer fields are 64 bits wide, your module has only allocated 32 bits for them. Here's a correct example of mixing 32 and 64 bit pointers: #include main() { char *format1 = "sizeof(format1) = %d\n"; #pragma pointer_size (short) char *format2 = "sizeof(format2) = %d\n"; fprintf(stdout, format1, sizeof(format1)); fprintf(stdout, format2, sizeof(format2)); } I called this program "ron.c" and compiled it with cc -o ron -xtaso -taso ron.c Running the program yields: sizeof(format1) = 8 sizeof(format2) = 4 The "-xtaso" flag simply tells the compiler to pay attention to the "#pragma pointer_size" directives (which are compiler directives, not preprocessor commands, in spite of the #). If you compiled the same program without -xtaso, then the #pragma would be ignored. Possible pragmas: #pragma pointer_size (short) means declarations use 32-bit pointers until otherwise specified #pragma pointer_size (long) means declarations use 64-bit pointers until otherwise specified #pragma pointer_size (save) saves current pointer-size on a stack of some sort #pragma pointer_size (restore) pops the stack value (It's not my fault that they used "short" here to mean "32 bits".) As far as I can tell, "-xtaso_short" really means "-xtaso, but also insert a #pragma pointer_size (short) at the start of the module." As you've found out, this is not such a good idea because most modules include header files that declare structures that are shared with 64-bit library routines. Generally, sticking a "#pragma pointer_size (short)" after all the system #includes does the right thing. But there is one nasty surprise still lurking. The declaration #pragma pointer_size (short) char **argv; declares argv as a 32-bit pointer to an array of 32-bit pointers. However, if this is the usual argv, it's already set up as a pointer to an array of 64-bit pointers by the exec() mechanism, and so you can't declare argv while "short" pointers are enabled. I suppose the type-safe thing to do would be something like #pragma pointer_size (long) typedef char *argv_element; #pragma pointer_size (short) argv_element *argv; but that's a lot of extra bother. I just convert the usual declaration of main() to look like: main(argc, argv) #pragma pointer_size (save) #pragma pointer_size (long) int argc; char **argv; #pragma pointer_size (restore) { and everything is cool. I supposed it would be neat if the compiler could be trained to do some of this automagically, but it's not that hard to do it by hand. In fact, most programs with large numbers of pointers have relatively few important pointer types, and if you just surround the declarations of those specific types with #pragma pointer_size (save) #pragma pointer_size (short) typedef struct whatever *whateverp; #pragma pointer_size (restore) your data size should shrink nicely. -Jeff