Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Preprocessor Overheads Date: Wed, 01 Feb 2017 17:36:47 -0800 Organization: None to speak of Lines: 100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="523b5027be519a02b651eac1ee0346e8"; logging-data="1546"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uBiEe/dr3W2wb03Tm7MNb" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:UHvGWNh/zKW1l8YSUXHUrL43zfc= sha1:KamUOQZ+2hnzUYGgVlu8tyZ4ZbM= Xref: csiph.com comp.lang.c:102940 BartC writes: [...] > (2) Printing pointer values. > > Presumably this is what "%p" is for. Yes. > But apparently %p should only be > used for void* types, so requiring a cast in most cases. Yes, using any other type (other than a character pointer type) has undefined behavior. The casts are hardly pointless. They're necessary if you want to write (or generate) valid C. > (3) Printing 64-bit values. > > This one I don't understand: > > #include > #include > ... > int64_t aa = 0; > printf("%lld\n", aa); > > gcc gives me: "warning: unknown conversion type character 'l' in > format". Are you using a very old version of gcc, or with some odd options? The "%lld" format has been standard since C99. If you're using "-ansi" or "-std=c90", then you're telling the compiler you don't want to use some features that you're using. [...] > At least gcc on Linux can be shut up by using "%ld". But what format to > use that works on Windows, and works also on Linux for the same type, > int64_t? int64_t might be defined as long or as long long (or, in principle, as any of several other types). Either use the PRId64 macro from , or convert to long long and use "%lld". > (4) 'Too many arguments for format' > > This one line: > > printf("%lld%s",l.value," "); > > generates 3 warnings: > > "warning: unknown conversion type character 'l' in format" > "warning: format '%s' expects argument of type 'char *', but argument > 2 has type 'int64 {aka long long int}" > "warning: too many arguments for format" > > l.value has int64_t type. What's it moaning about here? That line doesn't appear in the clex.c file I thought we were talking about. But again, any modern gcc will recognize "%lld" -- but see above for the corrct way to print an int64_t value. [...] > (6) Zero-length arrays > > This is an error not a warning, but I think it came about while I was > trying to suppress a warning (to do with using {} for initialising I think): > > int data[]; // or: > int data[] = {}; > > Apparently this is a no-no. But sometimes this is exactly what you want, > for example when you have a set of such arrays, some may be filled, some > could be empty waiting to be set up at some later date or by someone > else. But in the meantime, it won't compile. Right, it won't compile, because zero-length arrays do not exist in C. And you're complaining that your compiler tells you this? > (7) Converting between void* and function pointers. > > This seems to be frowned upon. But it's difficult to add a cast, when > there are multiple pointers that must all be coerced to the same time, > where the functions are all mixed types. (I think Tim has done something > to fix that, but whatever it is, I don't think I can do the same. Nor do > I want the clutter.) You can convert (using a cast) from any function pointer type to any other function pointer type. If you need a generic function pointer type, just pick one, such as `void(*)(void)`. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"