Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is this syntactically valid C++?

Reply
Thread Tools

Is this syntactically valid C++?

 
 
Alan Mackenzie
Guest
Posts: n/a
 
      08-14-2010
Here is a fragment from an old test case in Emacs's C++ Mode:

1 class CLS {
2 int i; float f; char *s;
3 }
4 cls_1 /* ; */ (1,
5 1.0,
6 "foo"
7 ),
8 cls_2 (2, -1.0, "bar");

.. Noting that the bracketing characters on lines 4, 7 and 8 are
parentheses (not braces), is this coherent C++? If so, what sort of
identifiers are "cls_1" and "cls_2"?

At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
functions. If the fragment is coherent C++, this might be the wrong
thing to do. On the other hand, If the fragment is nonsense, it doesn't
really matter.

Please, somebody, help me out with this puzzling bit of code. Thanks in
advance!

--
Alan Mackenzie (Nuremberg, Germany).

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      08-14-2010
Alan Mackenzie wrote:

> Here is a fragment from an old test case in Emacs's C++ Mode:
>
> 1 class CLS {
> 2 int i; float f; char *s;
> 3 }
> 4 cls_1 /* ; */ (1,
> 5 1.0,
> 6 "foo"
> 7 ),
> 8 cls_2 (2, -1.0, "bar");


Let's write this without the irritating comments and line breaks:

class CLS {
int i; float f; char *s;
}
cls_1 (1, 1.0, "foo"),
cls_2 (2, -1.0, "bar");

which is the same as:

class CLS {
int i; float f; char *s;
};

CLS cls_1 (1, 1.0, "foo");
CLS cls_2 (2, -1.0, "bar");


> . Noting that the bracketing characters on lines 4, 7 and 8 are
> parentheses (not braces), is this coherent C++?


Syntactically, it seems correct, but the class is missing a constructor.

> If so, what sort of
> identifiers are "cls_1" and "cls_2"?


They are instances of the class CLS.

> At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
> functions. If the fragment is coherent C++, this might be the wrong
> thing to do.


I don't see how cls_1 and cls_2 could be functions. In a function call, you
don't specify a return type, and in a function declaration, you need to
specify argument types, not values.

 
Reply With Quote
 
 
 
 
Alan Mackenzie
Guest
Posts: n/a
 
      08-14-2010
Hi, Rolf!

Rolf Magnus <> wrote:
> Alan Mackenzie wrote:


>> Here is a fragment from an old test case in Emacs's C++ Mode:


>> 1 class CLS {
>> 2 int i; float f; char *s;
>> 3 }
>> 4 cls_1 /* ; */ (1,
>> 5 1.0,
>> 6 "foo"
>> 7 ),
>> 8 cls_2 (2, -1.0, "bar");


> Let's write this without the irritating comments and line breaks:


> class CLS {
> int i; float f; char *s;
> }
> cls_1 (1, 1.0, "foo"),
> cls_2 (2, -1.0, "bar");


> which is the same as:


> class CLS {
> int i; float f; char *s;
> };


> CLS cls_1 (1, 1.0, "foo");
> CLS cls_2 (2, -1.0, "bar");



>> . Noting that the bracketing characters on lines 4, 7 and 8 are
>> parentheses (not braces), is this coherent C++?


> Syntactically, it seems correct, but the class is missing a constructor.


OK, Thanks!

>> If so, what sort of identifiers are "cls_1" and "cls_2"?


> They are instances of the class CLS.


Ah!

>> At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
>> functions. If the fragment is coherent C++, this might be the wrong
>> thing to do.


> I don't see how cls_1 and cls_2 could be functions.


They were (naively) recognised as functions because of the open
parenthesis (not brace) following the identifier.

> In a function call, you don't specify a return type, and in a function
> declaration, you need to specify argument types, not values.


Looks like I've got some work to do to highlight these identifiers as
variables.

Thanks for such a quick and helpful reply.

--
Alan Mackenzie (Nuremberg, Germany).

 
Reply With Quote
 
zoomzoom
Guest
Posts: n/a
 
      08-14-2010
On Aug 14, 12:02*pm, Alan Mackenzie <a...@muc.de> wrote:
> Here is a fragment from an old test case in Emacs's C++ Mode:
>
> 1 class CLS {
> 2 * * int i; float f; char *s;
> 3 }
> 4 * * cls_1 /* ; */ (1,
> 5 * * * * * * * * * *1.0,
> 6 * * * * * * * * * *"foo"
> 7 * * * * ),
> 8 * * cls_2 (2, -1.0, "bar");
>
> . *Noting that the bracketing characters on lines 4, 7 and 8 are
> parentheses (not braces), is this coherent C++? *If so, what sort of
> identifiers are "cls_1" and "cls_2"?
>
> At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
> functions. *If the fragment is coherent C++, this might be the wrong
> thing to do. *On the other hand, If the fragment is nonsense, it doesn't
> really matter.
>
> Please, somebody, help me out with this puzzling bit of code. *Thanks in
> advance!
>
> --
> Alan Mackenzie (Nuremberg, Germany).


Sorry it is not a correct C++ fragment; There is no CLS constructor
which takes an int, float and const char * as arguments. The C++
compiler will only generate a the no argument and copy constructor
which respectively takes no arguments and a reference to a CLS
instance, i.e. CLS::CLS() and CLS::CLS(const CLS &). The intent may
have been to do the following

class CLS {
int i, float f, char *s;
// Note the following 3 lines
public:
CLS(int _i, float _f, char *_s): i(_i), f(_f), s(_s){}
} cls_1(1, 1.0, "foo"),
cls_2(2, -1.0, "bar");
 
Reply With Quote
 
zoomzoom
Guest
Posts: n/a
 
      08-14-2010
On Aug 14, 12:02*pm, Alan Mackenzie <a...@muc.de> wrote:
> Here is a fragment from an old test case in Emacs's C++ Mode:
>
> 1 class CLS {
> 2 * * int i; float f; char *s;
> 3 }
> 4 * * cls_1 /* ; */ (1,
> 5 * * * * * * * * * *1.0,
> 6 * * * * * * * * * *"foo"
> 7 * * * * ),
> 8 * * cls_2 (2, -1.0, "bar");
>
> . *Noting that the bracketing characters on lines 4, 7 and 8 are
> parentheses (not braces), is this coherent C++? *If so, what sort of
> identifiers are "cls_1" and "cls_2"?
>
> At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
> functions. *If the fragment is coherent C++, this might be the wrong
> thing to do. *On the other hand, If the fragment is nonsense, it doesn't
> really matter.
>
> Please, somebody, help me out with this puzzling bit of code. *Thanks in
> advance!
>
> --
> Alan Mackenzie (Nuremberg, Germany).


And cls_1 and cls_2 are intances of class CLS.
 
Reply With Quote
 
joe
Guest
Posts: n/a
 
      08-15-2010
I select the OP's subjectline (remember when we were young (?): subject
line (2 words, not one), THOSE were the days!). By "definition", you're
old when you don't care about whether your parenthesis all close
correctly. Actually, parenthesis are for oldsters! "Youth is wasted on
the young". (Unless you are a celeb, of course, then .. nevermind).

"Are all the parenthesis in the above OK?" == "Is this .. blah, blah".
It's always the same day, I assure you, and tomorrow the same song will
play on the clock radio.


 
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
Is this syntactically valid Java? Christopher Benson-Manica Java 16 11-29-2007 05:15 PM
syntactically comprehensive test program nobrow@gmail.com C Programming 6 02-28-2007 10:59 PM
Not valid SSID name during setup using the wizard =?Utf-8?B?SE1WYWNhbmE=?= Wireless Networking 4 08-23-2005 05:38 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 3 04-27-2005 09:20 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 0 04-26-2005 06:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57