is this compilation right?

W

wenmang

Hi,

Here is a function:
void f(const char *){};

when I call above function with following statement, it is compiled
without error:
f(string("hi")); //create a tmp string object

Is it right for compiler not even issuing an error?

wm
 
V

Victor Bazarov

Here is a function:
void f(const char *){};

The semicolon after it is most likely redundant (or even harmful).
when I call above function with following statement, it is compiled
without error:
f(string("hi")); //create a tmp string object

Is it right for compiler not even issuing an error?

Shouldn't. Unless you redefined 'string' somehow not to mean
'std::string'. What is 'string'? Post _complete_ code that you
claim compiles without an error.

V
 
G

Greg Comeau

The semicolon after it is most likely redundant (or even harmful).

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 1: error: extra ";" ignored,
In C: A function definition does not end with a semicolon
In C++: A function definition, extern "C" or namespace,
does not end with a semicolon
void f(const char *){};
^

1 error detected in the compilation of "ComeauTest.c".
 
V

Victor Bazarov

Greg said:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 1: error: extra ";" ignored,
In C: A function definition does not end with a semicolon
In C++: A function definition, extern "C" or namespace,
does not end with a semicolon
void f(const char *){};
^

1 error detected in the compilation of "ComeauTest.c".

Yes. It would be only redundant if the function is a member. That's
why I requested the complete code.

V
 
W

wenmang

This is not real code that I was using.

Here is the question, unfortunately, the include path for our Makefile
includes too many possible file with the same name, e.g., map which
from Roguewave and SGI, etc.
Do I have the way to decipher my final build(maybe partial if necessay
or with certain compiler option?) to see what exact the header file is
included and from where?
Thanks.
 
W

wenmang

The reason I am asking is that we have pre-std C++ with name like map.h
provided by vendor, and at the same time, SGI and other library with
std C++ are also installed on our unix box. Imaginge that confusion we
have had.
 
M

mlimber

This is not real code that I was using.

Here is the question, unfortunately, the include path for our Makefile
includes too many possible file with the same name, e.g., map which
from Roguewave and SGI, etc.
Do I have the way to decipher my final build(maybe partial if necessay
or with certain compiler option?) to see what exact the header file is
included and from where?
Thanks.

There may be a compiler-specific verbosity option that you can use, or
you could dump the preprocessor output and dig through it. Usually, the
PP will emit #line statements with the fully qualified filename and
line number.

Cheers! --M
 
V

Victor Bazarov

This is not real code that I was using.

Here is the question, unfortunately, the include path for our Makefile
includes too many possible file with the same name, e.g., map which
from Roguewave and SGI, etc.
Do I have the way to decipher my final build(maybe partial if necessay
or with certain compiler option?) to see what exact the header file is
included and from where?

Try generating dependencies -- that should show the exact file names.
Project management is OT here, unfortunately.

V
 
V

Victor Bazarov

The reason I am asking is that we have pre-std C++ with name like map.h
provided by vendor, and at the same time, SGI and other library with
std C++ are also installed on our unix box. Imaginge that confusion we
have had.

Seven years after the Standard has been approved... It may be time for
you to straighten out your build environment. Just a thought.

V
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top