This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Request for compiler option to disable multiple declarations in a single statement
- From: Manish Jain <bourne dot identity at hotmail dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 19 Apr 2018 08:09:49 +0000
- Subject: Request for compiler option to disable multiple declarations in a single statement
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