Warning in aCC - HP-UX

S

Shan

Hi All,
When i compile a code in HP-UX using aCC i am getting the following
warning. I am not able to understand this warning. Any help in
understanding the warning is appreciated.

shan 150 aCC -o TransTest TransTest.cpp
Warning 829: "TransTest.cpp", line 22 # Implicit conversion of string
literal to 'char *' is deprecated.
char * clear="clear";
^^^^^^^

The code snippet is:
char * clear = "clear";
system(clear);


Thanks in advance,
Shan
 
A

Artie Gold

Shan said:
Hi All,
When i compile a code in HP-UX using aCC i am getting the following
warning. I am not able to understand this warning. Any help in
understanding the warning is appreciated.

shan 150 aCC -o TransTest TransTest.cpp
Warning 829: "TransTest.cpp", line 22 # Implicit conversion of string
literal to 'char *' is deprecated.
char * clear="clear";
^^^^^^^
make that: const char * clear = "clear";
(In C++ string literals are const.)
The code snippet is:
char * clear = "clear";
system(clear);
HTH,
--ag
 
J

Jonathan Mcdougall

Shan said:
Hi All,
When i compile a code in HP-UX using aCC i am getting the following
warning. I am not able to understand this warning. Any help in
understanding the warning is appreciated.

shan 150 aCC -o TransTest TransTest.cpp
Warning 829: "TransTest.cpp", line 22 # Implicit conversion of string
literal to 'char *' is deprecated.
char * clear="clear";
^^^^^^^

The code snippet is:
char * clear = "clear";
system(clear);

String literals are const. For example,

char *test = "hello";
test[1] = 'a';

is undefined behavior and might crash your program.

const char *test = "hello";
test[1] = 'a'; // does not compile

The reason for which the first example compiles
fine (with warnings) is that there is a deprecated
implicit conversion from char* to const char* to
keep legacy code valid. That conversion should
not be used in new code.


Jonathan
 

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
474,196
Messages
2,571,036
Members
47,631
Latest member
kukuh

Latest Threads

Top