Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Initializer lacking assignment

0 views
Skip to first unread message

Bujor D Silaghi

unread,
Dec 3, 2002, 4:12:02 PM12/3/02
to bu...@cs.umd.edu

Hi everybody. Would anyone know what C standard a statement like:

int a 1;

adheres to, and whether or not there are modern compilers accepting it?

Regards,
Bujor

A. Sinan Unur

unread,
Dec 3, 2002, 4:39:13 PM12/3/02
to
Bujor D Silaghi <bu...@cs.umd.edu> wrote in
news:Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu:

>
> Hi everybody. Would anyone know what C standard a statement like:
>
> int a 1;
>
> adheres to, and whether or not there are modern compilers accepting it?

isn't that a syntax error?

--
A. Sinan Unur
as...@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:u...@ftc.gov

Emmanuel Delahaye

unread,
Dec 3, 2002, 4:42:32 PM12/3/02
to
In 'comp.lang.c', Bujor D Silaghi <bu...@cs.umd.edu> wrote:

> int a 1;

This is not C at all.

You probably meant

int a = 1;

--
-ed- emdel at noos.fr ~]=[o
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/manuals/reader.aspx
"Mal nommer les choses c'est ajouter du malheur au monde."
-- Albert Camus.

Blah

unread,
Dec 3, 2002, 4:41:46 PM12/3/02
to
*** post for FREE via your newsreader at post.newsfeed.com ***


"Emmanuel Delahaye" <emdel...@noos.fr> wrote in message
news:Xns92D9E701FB1...@130.133.1.4...


> In 'comp.lang.c', Bujor D Silaghi <bu...@cs.umd.edu> wrote:
>
> > int a 1;
>
> This is not C at all.
>
> You probably meant
>
> int a = 1;

Judging by the subject line, I think Bujor either meant

int a;

or wanted to know if some random C standard and/or compilers exist that
accept

int a 1;

Unless that's the message the compiler spit out when it saw "int a 1;", in
which case you're dead on. I don't know.


-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----

Micah Cowan

unread,
Dec 3, 2002, 4:57:37 PM12/3/02
to

Unless there's a

#define a foo=

somewhere above, that's a syntax error.

-Micah

--
Now available for part-time and full-time permanent or contract
positions in the Sacramento, CA (USA) area (or telecommute). Yes, it's
my real email address.

Emmanuel Delahaye

unread,
Dec 3, 2002, 5:20:25 PM12/3/02
to
In 'comp.lang.c', Micah Cowan <mi...@cowan.name> wrote:

>> int a 1;
>>
>> adheres to, and whether or not there are modern compilers accepting it?
>
> Unless there's a
>
> #define a foo=

He he! Twitsy!

Eric Sosman

unread,
Dec 3, 2002, 4:58:10 PM12/3/02
to
"A. Sinan Unur" wrote:
>
> Bujor D Silaghi <bu...@cs.umd.edu> wrote in
> news:Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu:
>
> >
> > Hi everybody. Would anyone know what C standard a statement like:
> >
> > int a 1;
> >
> > adheres to, and whether or not there are modern compilers accepting it?
>
> isn't that a syntax error?

Not in ANSI/ISO C. (By "ANSI/ISO," of course, I mean
"Arrogant Nitwits Syphilitically Inflamed/Intergalactic
Sniffling Orangutans" -- but that was obvious, surely.)

Compilers that accept this construct without complaint
are not properly described as "modern," but as "clueless."

--
Eric....@sun.com

Chris Torek

unread,
Dec 3, 2002, 5:07:16 PM12/3/02
to
In article <Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu>

Bujor D Silaghi <bu...@cs.umd.edu> writes:
>Hi everybody. Would anyone know what C standard a statement like:
>
> int a 1;
>
>adheres to ...

None. This is the form of initialization that was used in V6 C,
in the mid-1970s. It was replaced with the usual "int a = 1" syntax
before 1980, a decade before the first C standard.

>and whether or not there are modern compilers accepting it?

Any modern compiler must issue "at least one" diagnostic for the
above (providing you have not done #define tricks to replace "a"
with "b =" or some such). Having done so, they are then free to
accept or reject the translation unit.
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)
Domain: to...@bsdi.com http://67.40.109.61/torek/ (for the moment)
(you probably cannot email me -- spam has effectively killed email)

Goran Larsson

unread,
Dec 3, 2002, 5:39:32 PM12/3/02
to
In article <Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu>,

Bujor D Silaghi <bu...@cs.umd.edu> wrote:

> Hi everybody. Would anyone know what C standard a statement like:
>
> int a 1;
>
> adheres to,

C99 standard? No.
C89 standard? No.
K&R "standard"? No.
Pre-K&R? Yes.

This form of variable initialization is very ancient. A document from
1974 by Brian W. Kernighan (this is from before Kernighan and Ritchie
published the "The C Programming Language") describing this form is
available here:

< http://www.lysator.liu.se/c/bwk-tutor.html#initialization >

Note that this old version also used reversed assignment operators, i.e.
"x =- y" instead of "x -= y". This was later changed to get away from the
problems with having "x=-5" do the same as "x =- 5" instead of "x = -5"
that most programmers expected.

> and whether or not there are modern compilers accepting it?

I doubt any modern compiler will accept this form.

--
Göran Larsson http://www.mitt-eget.com

Bujor D Silaghi

unread,
Dec 3, 2002, 5:47:45 PM12/3/02
to

Thanks for all replies. Well, there's at least one RSX compiler that
accepts the statement. I was wondering if any of the more recent compilers
would accept it, though none that I tried so far did.

Bujor

Dan Pop

unread,
Dec 4, 2002, 6:37:40 AM12/4/02
to

The first C book ever published, K&R1, describes this feature as an
anachronism.

Beware: the compiler that accepts it may also accept =op as a replacement
for op=, with the "interesting" consequence that i=-1 means i -= 1 and
not i = -1. I was actually bitten by this as a beginner, when using an
old (pre-ANSI) VAX C compiler. The assembly listing clearly showed that
i was decremented and I couldn't understand why. Then, I remembered the
anachronisms section at the end of Appendix A and everything was clear.

Ever since, I always surrounded the binary operators by spaces, to be
sure that my expressions are parsed as intended. Nowadays, I do it
exclusively for readability purposes, the anachronic operators not
being supported by standard C.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan...@ifh.de

Arthur J. O'Dwyer

unread,
Dec 4, 2002, 12:19:10 PM12/4/02
to

On 4 Dec 2002, Dan Pop wrote:
>
> In <Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu> Bujor D Silaghi <bu...@cs.umd.edu> writes:
[discussion of old code fragment "int x 1;"]

> >Thanks for all replies. Well, there's at least one RSX compiler that
> >accepts the statement. I was wondering if any of the more recent compilers
> >would accept it, though none that I tried so far did.
>
> The first C book ever published, K&R1, describes this feature as an
> anachronism.

Yay K&R1!
Since I don't see it online, I'll post K&R's rationale for the change.

-Arthur

<quote>-------------------------------------------------------------

17. Anachronisms
Since C is an evolving language, certain obsolete constructions may be
found in older programs. Although most versions of the compiler support
such anachronisms [--as of 1978--], ultimately they will disappear,
leaving only a portability problem behind.
Earlier versions of C used the form =op instead of op= for assignment
operators. This leads to ambiguities, typified by

x=-1

which actually decrements x since the = and the - are adjacent, but
which might easily be intended to assign -1 to x.
The syntax of initializers has changed: previously, the equals sign the
introduces an initializer was not present, so instead of

int x = 1;

one used

int x 1;

The change was made because the initialization

int f (1+2)

resembles a function declaration closely enough to confuse the compilers.

</quote>------------------------------------------------------------

Mr. XXXX

unread,
Dec 4, 2002, 4:52:30 PM12/4/02
to
Bujor D Silaghi <bu...@cs.umd.edu> wrote in
news:Pine.SOL.4.33.02120...@crackerjack.cs.umd.edu:

>
> Hi everybody. Would anyone know what C standard a statement like:
>
> int a 1;

That's an error unless it's expanded to something meaningful by a
preprocessor stunt.

0 new messages