Article View: comp.std.c
Article #4024Re: A new programming language
From: Ian Cargill
Date: Mon, 18 Sep 1995 18:29
Date: Mon, 18 Sep 1995 18:29
67 lines
2406 bytes
2406 bytes
In article <DF3Evn.ICt@csc.liv.ac.uk> s5sem@csc.liv.ac.uk writes:
>In article <bbkhx*h8d@yaps.rhein.de>, arno@yaps.rhein.de (Arno Eigenwillig)
> writes:
>> In article <42om0g$qi6@mirv.unsw.edu.au>, Avi Pilosof writes:
>>
>> > The one thing I hate about C is that you
>> > cannot initialise a struct using curly braces at any point other
>> > that global scope.
>>
>> Wrong.
>>
>> -- __
>> __/// Arno Eigenwillig /\ <arno@yaps.rhein.de> \/ PGP key
>> \XX/ V+49-2225-5870 /\ <Arnooo @ #amigager> \/ available
>
>No, this is correct. Structures cannot be pre-initialised except as
>global. Maybe you were thinking of structure definitions ???
>
>-FISH- ><>
>
No, this is incorrect. Wrong was right. :-) :-)
6.5.7 (Constraints) says:
# The initializer for a structure or union object that
# has **automatic storage duration** either shall be an (my emphasis)
# initializer list as described below, or shall be a single
# expression that has compatible structure or union type. In
# the latter case, the initial value of the object is that of
# the expression.
So the following program is OK.
--- start of program ---
#include <stdio.h>
struct st{int num;char *s;};
struct st obj0 = {4, "four"};
void func( void )
{
/* not global scope ! */
struct st obj1 = {5, "five"}; /* initialiser list */
struct st obj2 = obj0; /* compatible structure type */
printf("%d, %s\n", obj1.num, obj1.s );
printf("%d, %s\n", obj2.num, obj2.s );
return;
}
int main(void)
{
func();
return 0;
}
--- end of program ---
--
============================================================================
Ian Cargill CEng MIEE | Find out about the Association of C and C++ Users
Soliton Software Ltd. | info@accu.org OR http://bach.cis.temple.edu/accu
Technical Details
Message-ID:
<811448951snz@soliton.demon.co.uk>Path:
arc1-ca.pugleaf.net!mail2news.demon.co.uk!soliton.demon.co.ukReferences:
<42h7q1$6qc@news.xs4all.nl> <42om0g$qi6@mirv.unsw.edu.au> <bbkhx*h8d@yaps.rhein.de> <DF3Evn.ICt@csc.liv.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!soliton.demon.co.uk From: Ian Cargill <ian@soliton.demon.co.uk> Newsgroups: comp.std.c Subject: Re: A new programming language Date: Mon, 18 Sep 95 18:29:11 GMT Organization: Soliton Software Ltd. Message-ID: <811448951snz@soliton.demon.co.uk> References: <42h7q1$6qc@news.xs4all.nl> <42om0g$qi6@mirv.unsw.edu.au> <bbkhx*h8d@yaps.rhein.de> <DF3Evn.ICt@csc.liv.ac.uk> Reply-To: ian@soliton.demon.co.uk X-NNTP-Posting-Host: soliton.demon.co.uk X-Newsreader: Simple NEWS 2.0 (ka9q DIS 1.24)