On 4/19/18, Manish Jain <bourne.ident...@hotmail.com> wrote: > Hi all, > > One of the historical artefacts of the C language has been the burden of > lugging around multiple declarations in a single statement, with some > well-known pitfalls: > > int* ptr1, ptr2; > > Since ptr2 looks like a pointer but actually is not, standard coding > guidelines recommend declaring like this: > > int *p1, *p2; > > If anything, this leads to bizarre statements - very misleading for > those trying to understand pointer usage in C or just read code: > > int i; > int *j = &i; // impression: *j is being assigned &i > > char *k = "Text"; // impression: *k is "Text" > > void *fx(char *z); // impression: *fx is will accept char & return void > > > Each of these idiosyncrasies is best avoided by retaining the space > after the asterisk (and removing the one before) in a pointer > declaration. This really ought to be the standard coding guideline. > > As for the problem of multiple declarations fraught in the suggestion > above, I would like gcc developers to please consider a compiler option > (--single-declarations perhaps) under which the programmer can only > introduce one declaration in one statement. If such an option could be > made available, it takes care of all declaration woes and lets declared > types bear close resemblance to what they appear to be from signatures. > > Would my idea have takers on this list ? > > -- > Thank you & Regards, > Manish Jain >
Clang has a warning flag called -Wcomma to warn about code like this; perhaps GCC could add it as well.