public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Manish Jain <bourne.identity@hotmail.com>
To: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Request for compiler option to disable multiple declarations in a single statement
Date: Thu, 19 Apr 2018 08:35:00 -0000	[thread overview]
Message-ID: <VI1PR02MB120069566F352087BFB27930F6B50@VI1PR02MB1200.eurprd02.prod.outlook.com> (raw)

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

             reply	other threads:[~2018-04-19  8:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19  8:35 Manish Jain [this message]
2018-04-19  9:22 ` David Brown
2018-04-19  9:39   ` Manish Jain
2018-04-19 15:41     ` David Brown
2018-04-19  9:28 ` Jonathan Wakely
2018-04-19 15:45   ` Manish Jain
2018-04-19 17:17     ` Jonathan Wakely
2018-04-19 22:08 ` Eric Gallager

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=VI1PR02MB120069566F352087BFB27930F6B50@VI1PR02MB1200.eurprd02.prod.outlook.com \
    --to=bourne.identity@hotmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).