Bug in code or bug in cl?

G

Gus Gassmann

I have a short code snippet here that gives me a curious compiler
warning.

int DGG_nicefyConstraint( const void */*solver_ptr*/,
DGG_data_t *data,
DGG_constraint_t *cut)

The cl compiler in MSVisualStudio v9 reports

cgltwomir.cpp(1067) : warning C4138: '*/' found outside of comment.

Line 1067 is the first line of the code snippet. I am not sure if it
complains about the first occurence of '*/' in this line or the
second. I am not even sure if the code is correct or what it means.
Can someone help?

TIA
 
V

Victor Bazarov

Gus said:
I have a short code snippet here that gives me a curious compiler
warning.

int DGG_nicefyConstraint( const void */*solver_ptr*/,

Make it

int DGG_nicefyConstraint( const void * /*solver_ptr*/,

The tokenizer sees the first asterisk and keeps reading more until it
can't form a complete token any longer. So, the following slash (that
you intended as the beginning of the comment) is added to the asterisk
and is interpreted as a closing for a non-existent comment.
DGG_data_t *data,
DGG_constraint_t *cut)

The cl compiler in MSVisualStudio v9 reports

cgltwomir.cpp(1067) : warning C4138: '*/' found outside of comment.

Line 1067 is the first line of the code snippet. I am not sure if it
complains about the first occurence of '*/' in this line or the
second. I am not even sure if the code is correct or what it means.

It would be correct if you added a space after the first asterisk. The
name of the argument is optional. Apparently the function does not use
the first argument, so the author commented the name out to prevent the
warning about an unused argument.

V
 
J

James Kanze

int DGG_nicefyConstraint( const void * /*solver_ptr*/,
The tokenizer sees the first asterisk and keeps reading more
until it can't form a complete token any longer. So, the
following slash (that you intended as the beginning of the
comment) is added to the asterisk and is interpreted as a
closing for a non-existent comment.
It would be correct if you added a space after the first asterisk.

It's correct anyway. There is no */ token in C++, so the max
munch rule doesn't apply. And the compiler is only warning;
presumably the authors of the compiler felt that most occurances
of */ would be closing comments, and that one outside of a
comment was probably due to someone having forgotten to open the
comment.
 
M

Michael Tsang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gus said:
I have a short code snippet here that gives me a curious compiler
warning.

int DGG_nicefyConstraint( const void */*solver_ptr*/,
DGG_data_t *data,
DGG_constraint_t *cut)

The cl compiler in MSVisualStudio v9 reports

cgltwomir.cpp(1067) : warning C4138: '*/' found outside of comment.

Line 1067 is the first line of the code snippet. I am not sure if it
complains about the first occurence of '*/' in this line or the
second. I am not even sure if the code is correct or what it means.
Can someone help?

TIA

There is no bug. It's a warning, not an error.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkt2wy0ACgkQm4klUUKw07CJzQCfbRzqxjKHY8U+PT5GD8UwlKvw
+VQAn1fnt5u1OcrhtfOepVpktp7qSN27
=Fzx+
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top