473,414 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Are declarators optional?


In K&R (page 210, A8), "declaration" is defined to be:

declaration:
declaration-specifiers init-declarators-list(opt);

Later (3rd paragraph), it says that, "empty declarations are not
permitted".

According to the former definition of "declaration" (which specifies
"declarators" as
being optional) "empty declarations" should be permitted.

So i tried out the following program ...

/***************************/
#include <stdio.h>
#include <stdlib.h>

int main(void) {
int;

putchar('\n');
exit(0);
}
/**************************/

.... and compiled it using ...
$cc prog.c -ansi -pedantic
prog.c: In function 'main':
prog.c:5: warning: useless type name in empty declaration

So i got only a warning (not an error).

The final question would be:- "Are declarators(or "identifiers")
optional?

PS: I am using gcc 4.1 on Linux 2.6

Feb 1 '07 #1
2 1334
"chandanlinster" <ch************@gmail.comwrites:
In K&R (page 210, A8), "declaration" is defined to be:

declaration:
declaration-specifiers init-declarators-list(opt);

Later (3rd paragraph), it says that, "empty declarations are not
permitted".

According to the former definition of "declaration" (which specifies
"declarators" as
being optional) "empty declarations" should be permitted.

So i tried out the following program ...

/***************************/
#include <stdio.h>
#include <stdlib.h>

int main(void) {
int;

putchar('\n');
exit(0);
}
/**************************/

... and compiled it using ...
$cc prog.c -ansi -pedantic
prog.c: In function 'main':
prog.c:5: warning: useless type name in empty declaration

So i got only a warning (not an error).
As far as the standard is concerned, there are only diagnostics.
There is not distinction between warnings and errors.
The final question would be:- "Are declarators(or "identifiers")
optional?
I have not checked the standard because it is a curious case where the
compiler wins either way!

(a) If they are allowed (by the standard) then the compiler is still
permitted to issue a diagnostic provided it translates the program
(which it did).

(b) If they are not allowed, the compiler must issue a diagnostic
(which it did) but it *may*, if it so wishes, continue to translate
the program.

You could ask if the standard defines the meaning of:

#include <stdlib.h>

struct s1 { int x; int i; };
struct s2 { int x; int; };

int main(void)
{
return sizeof(struct s1) == sizeof(struct s2) ?
EXIT_SUCCESS : EXIT_FAILURE;
}

but then I'd have to look it up.

--
Ben.
Feb 1 '07 #2
chandanlinster wrote:
In K&R (page 210, A8), "declaration" is defined to be:

declaration:
declaration-specifiers init-declarators-list(opt);

Later (3rd paragraph), it says that, "empty declarations are not
permitted".

According to the former definition of "declaration" (which specifies
"declarators" as
being optional) "empty declarations" should be permitted.
Grammatically, they are.
So i tried out the following program ...

/***************************/
#include <stdio.h>
#include <stdlib.h>

int main(void) {
int;
This is syntactically valid, but a constraint violation. To simplify a
bit: a declaration must declare at least one name. This name could be
a declarator, but it could also be a tag name,
struct s;
or an enumeration constant.
enum { zero };
putchar('\n');
exit(0);
}
/**************************/

... and compiled it using ...
$cc prog.c -ansi -pedantic
prog.c: In function 'main':
prog.c:5: warning: useless type name in empty declaration

So i got only a warning (not an error).
As long as at least one diagnostic is issued, it's all good. The only
time a compiler /must/ reject a program is if it contains an #error
directive.
The final question would be:- "Are declarators(or "identifiers")
optional?
In some cases, yes. In others, no.

Feb 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Ayaz Ahmed Khan | last post by:
Can a variable containing, say, an integer value be used as size declarator for an array of integers? g++ does not complain, but other compilers, such as Visual C++/6.0, Borland Builder C++, Turbo...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
12
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
1
by: Tookelso | last post by:
Hello, I would like to have a group of elements which are *required* in one context, but each one is *optional* in another context. For example: I have a configuration file which has a...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
5
by: borophyll | last post by:
I have two questions. The first: does the declaration of an array parameter in a function prototype which uses the notation mean that the array must be a variable length array. That is, the...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.