This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: A TINY BUG


In article <34391696.27758E19@softway.com>,
Jason Zions  <jazz@softway.com> wrote:
>> I have found that the following bad code gives "exception" at run
>> time instead of error message at compilation time (b18 Win95):
>> 
>> #include <stdio.h>
>> main(){
>>         printf("%s\n",sizeof(long));
>> }
>
>No compiler will detect this error at compile-time.  The prototype for
>printf is (char *, ...); that is, no specific type information for
>anything except the first parameter.  A compiler would have to read the
>first parameter to figure out the expected types for the remaining
>args, and much of the time that first parameter is dynamically computed
>at runtime instead of being a static string.  There are a couple of
>lint-like programs that will catch this error with a
>compile-time-evaluatable format string, but that's the best you can do.
>
>Summary: learn more about the language before whining about compiler
>errors.  This is a programmer bug, not a compiler bug.

Actually, this is a little harsh since GCC does, in fact, have a compile
time __attribute__ option for checking the arguments to a printf.  If
the prototype for printf in /usr/include/stdio.h had included something like:

    __attribute__((format(printf, 1, 2)));

it would have detected that programmer error.
-- 
http://www.bbc.com/	cgf@bbc.com			"Strange how unreal
VMS=>UNIX Solutions	Boston Business Computing	 the real can be."
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]