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

is the brackets ([]) the comment symbols ?

40 views
Skip to first unread message

Alexey Maykov

unread,
Dec 12, 1997, 3:00:00 AM12/12/97
to

Hi !

One man told me that the following construction is legal for c:
int [10] a;
because square brackets is the kind of the komment symbol in the ansi c
standard, but VC++5.0 gives a compile error.
So, the question is, does the man wrong, or i did something wrong ?

Ron Natalie

unread,
Dec 12, 1997, 3:00:00 AM12/12/97
to

Alexey Maykov wrote:

> One man told me that the following construction is legal for c:
> int [10] a;
> because square brackets is the kind of the komment symbol in the ansi

He's wrong. Brackets are definitely not comments, but an important
syntactic element of both C and C++.

Comments are delimited by surrounding them with /* or */.
Also in C++, anything from // to the end of a line is a comment.

[] is used for pointer dereferencing and array declarations.
Your line is illegal.

int /* 10 */ a; // Make an int called a, with a comment in the middle.
int a[10]; // make an array called a of 10 ints.

Kurt Watzka

unread,
Dec 12, 1997, 3:00:00 AM12/12/97
to

"Alexey Maykov" <may...@chat.ru> writes:

>Hi !

>One man told me that the following construction is legal for c:
>int [10] a;

>because square brackets is the kind of the komment symbol in the ansi c
>standard, but VC++5.0 gives a compile error.
>So, the question is, does the man wrong, or i did something wrong ?

Did he give you that information on April 1st? Not only are square
brackets _not_ a comment symbol in C, but I fail to remember _any_
language that uses square brackets as a comment symbol.

int [10] a;

cannot be derived from anything in the C syntax that I am aware of.
The current definition of C knows just one kind of comments, and
that is

/* This is a comment */

Single line comments will be a feature of C9X, but I doublt that square
brackets will be used to denote comments in any future version of C.
Just imagine a language definition that states: An expression in
square brackets is a comment if it cannot be interpreted as anything else
in the current context.

Kurt

--
| Kurt Watzka Phone : +49-89-2178-2781
| wat...@stat.uni-muenchen.de

Ed Manet

unread,
Dec 14, 1997, 3:00:00 AM12/14/97
to

it looks to me as if your trying to declare an array of ten int's there.
The only comment symbols in VC++ or ANSI C are these:

// comments out text to the end of the line

/* everything inside this is a comment */

The man was pulling your chain, dude.

Alexey Maykov wrote in message <34915...@news.telekom.ru>...

Alexey Maykov

unread,
Dec 15, 1997, 3:00:00 AM12/15/97
to

Ed Manet wrote in message <671un4$bch$1...@news.flinet.com>...

>it looks to me as if your trying to declare an array of ten int's there.
>The only comment symbols in VC++ or ANSI C are these:
>
>// comments out text to the end of the line
>
>/* everything inside this is a comment */

May be you are right, but I sow in coding standards of my
organization another proof of my suugestion. There is a recomendation for
commenting source code:
/******************************
* Function that inputs and sorts an array
* [1] declare array
* [2] input array
* [3] sort array
*******************************/
int a[SIZE]; [1]
//.....
for( int i=0; i < SIZE; i++ ) [2]
//....
for( int i=0; i < SIZE; i++ ) [3]
As you can see here its a comment technique where you first put a plan of
the futeure work and then use references for that plan. For this references
you can use brackets. But this example do not compile by VC 5.0.

Alex Maykov, IMSI


Charles Krug

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Alexey Maykov wrote:

> int a[SIZE]; [1]
> //.....
> for( int i=0; i < SIZE; i++ ) [2]
> //....
> for( int i=0; i < SIZE; i++ ) [3]
> As you can see here its a comment technique where you first put a plan of
> the futeure work and then use references for that plan. For this references
> you can use brackets. But this example do not compile by VC 5.0.
>

Nope. That won't compile under any environment I've seen. That is a
typographic convention from a book, not C/C++ source code.
In order to accomplist what you want, use the "//" symbol:

int a[SIZE]; // [1]
//.....
for( int i=0; i < SIZE; i++ ) // [2]
//....
for( int i=0; i < SIZE; i++ ) // [3]


--
Charles Krug, Jr.

may...@gmail.com

unread,
Jun 16, 2016, 10:26:34 PM6/16/16
to
On Friday, December 12, 1997 at 12:00:00 AM UTC-8, Alexey Maykov wrote:
> Hi !
>
> One man told me that the following construction is legal for c:
> int [10] a;
> because square brackets is the kind of the komment symbol in the ansi c
> standard, but VC++5.0 gives a compile error.
> So, the question is, does the man wrong, or i did something wrong ?

Here is what that man said:

a[5] is the same as 5[a]

Robert Wessel

unread,
Jun 17, 2016, 12:29:30 AM6/17/16
to
It's not true for declarations, so "int 10[a]" doesn't work. OTOH,
when you access an array, you can write:

a[10] = 3;

-or-

10[a] = 3;

and accomplish the same thing. That's because the array accessor
essentially decays into a pointer expression. IOW, the two above
lines are equivalent to:

*(a+10) = 3;

-and-

*(10+a) = 3;

The later form ("10[a]") is primarily used to confuse newbies.

But it's in no way a comment.

David Brown

unread,
Jun 17, 2016, 3:52:13 AM6/17/16
to
True (within the right context). But that was considered an unfortunate
quirk of the language and very bad style 20 years ago when this thread
was started - it is even more so now.

It is good to be helpful and try to answer questions on Usenet, but I
doubt that the OP here has been holding his breath for the last two
decades, waiting for an answer!

Ian Collins

unread,
Jun 17, 2016, 6:47:46 AM6/17/16
to
On 06/17/16 02:26 PM, may...@gmail.com wrote:
> On Friday, December 12, 1997 at 12:00:00 AM UTC-8, Alexey Maykov wrote:

Time travel again...

--
Ian

Real Troll

unread,
Jun 17, 2016, 1:21:43 PM6/17/16
to
On 17/06/2016 08:51, David Brown wrote:
> It is good to be helpful and try to answer questions on Usenet, but I
> doubt that the OP here has been holding his breath for the last two
> decades, waiting for an answer!

He must have died by now!!!!!!!!!!

Richard

unread,
Jun 17, 2016, 1:35:36 PM6/17/16
to
[Please do not mail me a copy of your followup]

As others have already mentioned swapping the name of an array and
it's index may be valid syntax, but it is not recommended. Just because
something is allowed doesn't mean it's a good idea.

may...@gmail.com spake the secret code
<51b8cc80-a55c-4134...@googlegroups.com> thusly:

>Here is what that man said:
>
>a[5] is the same as 5[a]

For expressions in the C language, yes.

1 #include <stdio.h>
2
3 int main()
4 {
5 int a[1] = { 0 };
6 0[a] = 10;
7 printf("%d\n", a[0]);
8 return 0;
9 }

> gcc /tmp/a.c
> ./a.out
10

For expressions in the C++ language, no.

1 #include <iostream>
2 #include <vector>
3
4 int main()
5 {
6 std::vector<int> a(1);
7 0[a] = 10;
8 std::cout << a[0] << '\n';
9 return 0;
10 }

> g++ /tmp/a.cpp -o a2.out
/tmp/a.cpp: In function 'int main()':
/tmp/a.cpp:7:4: error: no match for 'operator[]' (operand types are 'int' and 'std::vector<int>')
0[a] = 10;
^
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages