Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > char array initialization: Is 'char a[] = ("a")' valid ANSI C?

Reply
Thread Tools

char array initialization: Is 'char a[] = ("a")' valid ANSI C?

 
 
Petter Reinholdtsen
Guest
Posts: n/a
 
      11-01-2004

Is the code fragment 'char a[] = ("a");' valid ANSI C? The
problematic part is '("a")'. I am sure 'char a[] = "a";' is valid
ANSI C, but I am more unsure if it is allowed to place () around the
string literal.
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      11-01-2004
On Mon, 01 Nov 2004 17:13:10 +0100
Petter Reinholdtsen <(E-Mail Removed)> wrote:

> Is the code fragment 'char a[] = ("a");' valid ANSI C? The
> problematic part is '("a")'. I am sure 'char a[] = "a";' is valid
> ANSI C, but I am more unsure if it is allowed to place () around the
> string literal.


Yes it is. I can't think of any situation where it is illegal to put
brackets around an expression.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
 
 
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      11-01-2004
Flash Gordon <(E-Mail Removed)> spoke thus:

> Yes it is. I can't think of any situation where it is illegal to put
> brackets around an expression.


Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
least in the parlance I'm familiar with.

On second thought, dictionary.com says "bracket" can mean
"parenthesis" in British English. Is one or the other standard, or
are we at the mercy of dialect here as in many other areas?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-01-2004
Christopher Benson-Manica <(E-Mail Removed)> writes:
> Flash Gordon <(E-Mail Removed)> spoke thus:
>
>> Yes it is. I can't think of any situation where it is illegal to put
>> brackets around an expression.

>
> Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
> least in the parlance I'm familiar with.
>
> On second thought, dictionary.com says "bracket" can mean
> "parenthesis" in British English. Is one or the other standard, or
> are we at the mercy of dialect here as in many other areas?


In my personal dialect of English, the terms are (parentheses),
[brackets], and {braces}. Other dialects may differ. I think the
term "parentheses" is unambiguous, but if there's any doubt it's best
to refer to [square brackets] and {curly braces}. Better yet, use the
characters themselves.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-01-2004
Keith Thompson wrote:
> Christopher Benson-Manica <(E-Mail Removed)> writes:
>
>>Flash Gordon <(E-Mail Removed)> spoke thus:
>>
>>
>>>Yes it is. I can't think of any situation where it is illegal to put
>>>brackets around an expression.

>>
>>Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
>>least in the parlance I'm familiar with.
>>
>>On second thought, dictionary.com says "bracket" can mean
>>"parenthesis" in British English. Is one or the other standard, or
>>are we at the mercy of dialect here as in many other areas?

>
>
> In my personal dialect of English, the terms are (parentheses),
> [brackets], and {braces}. Other dialects may differ. I think the
> term "parentheses" is unambiguous, but if there's any doubt it's best
> to refer to [square brackets] and {curly braces}. Better yet, use the
> characters themselves.


To avoid trouble with international keyboards and
displays, write "the characters themselves" in the form
??(square brackets:> and <%curly braces??>.



--
(E-Mail Removed)


 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      11-01-2004
On Mon, 01 Nov 2004 19:26:27 GMT
Keith Thompson <(E-Mail Removed)> wrote:

> Christopher Benson-Manica <(E-Mail Removed)> writes:
> > Flash Gordon <(E-Mail Removed)> spoke thus:
> >
> >> Yes it is. I can't think of any situation where it is illegal to
> >> put brackets around an expression.

> >
> > Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
> > least in the parlance I'm familiar with.
> >
> > On second thought, dictionary.com says "bracket" can mean
> > "parenthesis" in British English. Is one or the other standard, or
> > are we at the mercy of dialect here as in many other areas?

>
> In my personal dialect of English, the terms are (parentheses),
> [brackets], and {braces}. Other dialects may differ. I think the
> term "parentheses" is unambiguous, but if there's any doubt it's best
> to refer to [square brackets] and {curly braces}. Better yet, use the
> characters themselves.


Where I grew up (Hadleigh, Essex, England) brackets was the term used in
ordinary (as opposed to technical) English, parenthesis was only used in
maths classes.

I didn't particularly think about it in the above quote, or I would have
used parenthesis, but in any case as there was an example above I would
consider my post unambiguous.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      11-02-2004
Keith Thompson wrote:
>
> Christopher Benson-Manica <(E-Mail Removed)> writes:
> > Flash Gordon <(E-Mail Removed)> spoke thus:
> >
> >> Yes it is.
> >> I can't think of any situation where it is illegal to put
> >> brackets around an expression.

> >
> > Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
> > least in the parlance I'm familiar with.
> >
> > On second thought, dictionary.com says "bracket" can mean
> > "parenthesis" in British English. Is one or the other standard, or
> > are we at the mercy of dialect here as in many other areas?

>
> In my personal dialect of English, the terms are (parentheses),
> [brackets], and {braces}. Other dialects may differ. I think the
> term "parentheses" is unambiguous, but if there's any doubt it's best
> to refer to [square brackets] and {curly braces}. Better yet, use the
> characters themselves.


N869
Index
( ) (parentheses punctuator), 6.7.5.3, 6.8.4, 6.8.5
[ ] (brackets punctuator), 6.7.5.2, 6.7.8
{ } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8, 6.8.2

--
pete
 
Reply With Quote
 
Petter Reinholdtsen
Guest
Posts: n/a
 
      11-02-2004

[Flash Gordon]
> Yes it is. I can't think of any situation where it is illegal to put
> brackets around an expression.


I agree, but the authors of the HP aCC compiler and a bug reported
against GNU C compiler disagrees. See
<URL:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11250> for the GCC
bug report. I'm trying to find out if they are correct or not.

The HP aCC compiler reject the code with an error, and a future GCC
will issue a warning when using -pedantic.

I guess I need a good ANSI C lawyer. Anyone around?
 
Reply With Quote
 
Kevin Bracey
Guest
Posts: n/a
 
      11-02-2004
In message <(E-Mail Removed)-gordon.me.uk>
Flash Gordon <(E-Mail Removed)> wrote:

> On Mon, 01 Nov 2004 17:13:10 +0100
> Petter Reinholdtsen <(E-Mail Removed)> wrote:
>
> > Is the code fragment 'char a[] = ("a");' valid ANSI C? The
> > problematic part is '("a")'. I am sure 'char a[] = "a";' is valid
> > ANSI C, but I am more unsure if it is allowed to place () around the
> > string literal.

>
> Yes it is. I can't think of any situation where it is illegal to put
> brackets around an expression.


The problem is that that string literal isn't going in the place of an
expression. I'm pretty certain that it's illegal for basically the same
reason that these all are:

#include ("header.h")

char a[] = ({1,2});

char *a = "He" ("llo");

char a[]; a = "Hello";

The initialiser has required to be a string literal, it's not an expression.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      11-02-2004
Keith Thompson <(E-Mail Removed)> wrote:
> Christopher Benson-Manica <(E-Mail Removed)> writes:
> >
> > Did you mean to say "parentheses"? "Brackets" are '[' and ']', at
> > least in the parlance I'm familiar with.
> >

>
> In my personal dialect of English, the terms are (parentheses),
> [brackets], and {braces}. Other dialects may differ.


Mine has:
(brackets)
[square brackets]
{braces}
Sometimes 'curly braces' is used instead of braces.
'Parentheses' is used when you mean 'brackets' but want to
sound well-educated (or snooty).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
length of 2D Array >> char **myString= (char **) malloc (sizeof (char *)); davidb C++ 6 09-01-2006 05:57 PM
length of 2D Array >> char **myString= (char **) malloc (sizeof (char *)); davidb C++ 0 09-01-2006 03:22 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
Problem- strcat with char and char indexed from char array aldonnelley@gmail.com C++ 3 04-20-2006 07:32 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM



Advertisments