Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #72324
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: overuse of auto is dangerous |
| Date | 2020-03-16 13:29 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <r4nreq$qp1$1@dont-email.me> (permalink) |
| References | (6 earlier) <Gq8bG.543651$Bf2.462147@fx39.am4> <r4l3fp$v13$1@dont-email.me> <87tv2pqm0i.fsf@nosuchdomain.example.com> <r4nccf$3q0$1@dont-email.me> <XEJbG.376608$y87.218837@fx25.am4> |
On 16/03/2020 12:44, Bart wrote: > On 16/03/2020 08:11, David Brown wrote: >> On 15/03/2020 23:41, Keith Thompson wrote: > >>> Good reasons for using a different name for the same parameter in a >>> declaration and definition of a function? I can't think of any. > >> Parameter names can come in conflict with macros. In particular, >> system headers will often have parameter names that use implementation >> namespace to avoid conflict: >> >> extern void *memset(void *__s, int __c, size_t __n) >> >> It is perfectly allowed to write: >> >> #define s 1234 >> #define c 5678; >> #define n Humpty Dumpty >> #include <string.h> >> >> So the declaration in <string.h> can't use "s, c, n" as the parameters. > > There's something very wrong then. > > Parameter names are supposed to live in their own scope, which in a > function definition extends to the body of the function. Macros are not scoped. > > It also makes it impossible to use ANY identifier, since someone could > have used it for some macro. Or even any keyword, as someone could write > '#define if 1234'. Defining macro identifiers that are keywords, or any reserved identifier, is undefined behaviour in C and C++ (i.e., it's likely that things will go wrong, and the standards can't guarantee anything). Like it or not (and I know you don't like it!) that's the way macros in the preprocessor work in C and C++. It is a reason why more modern languages don't have a preprocessor of the same kind C and C++ do, and why modern C and C++ programmers usually avoid macros and the preprocessor if there are better alternatives. > > It would anyway make keyword parameters look very ugly if all those > double underlines are going to end up in user code. > > > It is perfectly allowed to write: > > > > #define s 1234 > > #define c 5678; > > #define n Humpty Dumpty > > So whose job is it to say DON'T DO THIS - language, compiler or > guidelines? And aren't macro names supposed to be in capitals? Guidelines. (No, macro names are /not/ "supposed to be in capitals". It is a common guideline, which is often useful - but often used as an alternative to thinking properly and using good names.) Every language has ways to write bad code. Does your compiler for your language complain if you call every function "f1", "f2", "f3", etc., and name your variables "O", "OO", "OOO", etc. ? I assume not - but if you were to write a set of guidelines for your language you would ban these (under a general "use sensible names" rule). (I'm saying how things are, not how I think they should be. C macros are extremely useful, and you need to understand them to write good C and to avoid some kinds of mistakes. It would be nicer if more mistakes were impossible to make in the language, but C is the way it is.)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-13 00:27 +0100
Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-13 00:27 +0000
Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-13 13:57 +1300
Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-12 18:16 -0700
Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-13 16:17 +1300
Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-12 20:48 -0700
Re: overuse of auto is dangerous "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-03-13 21:27 +0100
Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-13 13:35 -0700
Re: overuse of auto is dangerous Cholo Lennon <chololennon@hotmail.com> - 2020-03-12 22:06 -0300
Re: overuse of auto is dangerous Bo Persson <bo@bo-persson.se> - 2020-03-13 03:17 +0100
Re: overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-13 08:51 +0100
Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-13 01:14 -0700
Re: overuse of auto is dangerous Vir Campestris <vir.campestris@invalid.invalid> - 2020-03-16 21:35 +0000
Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-17 11:49 +1300
Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-13 21:27 +0100
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-13 11:07 +0100
Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-13 10:39 +0000
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-13 14:26 +0100
Re: overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-14 09:20 +0100
Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-14 10:12 -0400
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-14 16:12 +0100
Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-14 17:23 +0000
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-15 12:27 +0100
Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-15 15:41 -0700
Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-16 13:37 +1300
Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-16 07:26 +0000
Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-16 07:05 -0400
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 12:32 +0100
Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-16 08:21 -0400
Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-16 11:27 +0000
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 09:11 +0100
Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-16 11:44 +0000
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 13:29 +0100
Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-16 05:35 -0700
Re: overuse of auto is dangerous James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-16 09:16 -0400
Re: overuse of auto is dangerous Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-02 07:13 -0700
Re: overuse of auto is dangerous James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-02 07:45 -0700
Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 10:25 -0700
Re: overuse of auto is dangerous Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 12:49 -0700
Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-04-05 14:15 +0200
Re: overuse of auto is dangerous Paavo Helde <myfirstname@osa.pri.ee> - 2020-04-02 19:20 +0300
Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 10:19 -0700
Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-15 16:26 +0100
Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-13 07:27 -0700
Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-13 21:22 +0000
Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 04:53 +0000
Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-14 03:23 -0700
Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 13:20 +0000
Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-14 09:20 -0700
Re: overuse of auto is dangerous Paavo Helde <myfirstname@osa.pri.ee> - 2020-03-13 13:53 +0200
Re: overuse of auto is dangerous Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2020-03-13 15:46 +0000
Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-13 23:09 -0400
Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-14 08:06 +0100
Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 13:16 +0000
Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-16 15:31 +0100
csiph-web