From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fac41,af40e09e753872c X-Google-Attributes: gidfac41,public X-Google-Thread: f8c65,30e368bdb3310fe5 X-Google-Attributes: gidf8c65,public X-Google-Thread: 1014db,30e368bdb3310fe5 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,30e368bdb3310fe5 X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,f292779560fb8442 X-Google-Attributes: gid109fba,public X-Google-Thread: 1008e3,30e368bdb3310fe5 X-Google-Attributes: gid1008e3,public X-Google-Thread: 10db24,30e368bdb3310fe5 X-Google-Attributes: gid10db24,public From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) Subject: Re: Hungarian notation Date: 1996/05/23 Message-ID: #1/1 X-Deja-AN: 156305460 sender: news@lts.sel.alcatel.de references: <4adem2$b5s@mercury.IntNet.net> <4ahka7$o9m@inrou.erno.de> organization: GABI Software, Sarl. newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.edu,comp.lang.eiffel Date: 1996-05-23T00:00:00+00:00 List-Id: In article <31a3b1b5.442039268@sqarc> willer@carolian.com (Steve Willer) writes: |> kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) wrote: |> >This must be an amazingly brillant compiler... |> It is. It was written by the FSF people. It's called "gcc". :-) |> In particular, gcc checks the arguments of the printf family against the |> formatter string when the -Wall option is on (actually, I'm sure it's a |> specific warning, but I always use -Wall). |> It only warns with these specific functions; if you declare your own |> function that uses varargs and vsprintf, it won't check it. Yes, it's a |> hack, but it's a really _nice_ hack. You should have read the rest of my posting. Gcc does *NOT* check the arguments of the formatter string when that string is not a string literal. In practice, the string will in fact almost always be the return value of a function: gettext on X/Open systems, for example. In most cases, the string will not yet have been written at the time the code is compiled. Since the semantics of gettext are defined by the X/Open standard, gcc could presumably also recognize this, and treat it as a special hack. They could also provide a new gettext (or a wrapper function, which in fact is what I do in C++), which verifies that the conversion specifications are correct in the string read from disk. |> >This isn't to say I approve of Hungarian notation, even in C and used |> >with printf. Nor to criticize a compiler from generating a warning on |> >obviously bad code. Just that this warning won't really be as useful |> >as one would like in commercial software. |> You really think so? Perhaps I'm misunderstanding you. A common mistake |> around here is to write something like: |> printf("The number is %n\n",mynumber); |> ...which would only crash when the program hits this line of code, and |> then only if "mynumber" had a value that made it crash. I can't tell you |> how many times we've made this mistake and gcc's caught it (actually, I |> could probably guess: maybe 10 over the last year and a half). I've never had too much problem with this. In fact, I cannot remember a single occurance in 15 years of C/C++ programming. I *HAVE* been bitten by two conversion specifiers being swapped during translation. (I forgot to insert the X/Open positional specifiers when the word order changed.) Given that the actual translation may occur years after the program has been compiled and released, I really don't consider it a reproach to say that the compiler doesn't detect the error. -- James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France Conseils, �tudes et r�alisations en logiciel orient� objet -- -- A la recherche d'une activit� dans une region francophone