Solved

"Implicit conversion of string literal" during compilation

Posted on 2002-07-22
6
716 Views
Last Modified: 2007-12-19
Hi All,

I am beginner of C/C++ programming. Need You help/assist to solve my case, below is some warning messages displayed during compilation BS_LOGIC.c. Currently I am using HPUX 11 64-bit with c compiler and cpp compiler. About the warning messages, should I modify the code or maybe there is a particular option parameters following c/cpp can be used during compilation to make them compatible.

Thank You

Peter

Warning 829: "BS_LOGIC.c", line 465 # Implicit conversion of string literal to
    'char *' is deprecated.
         "declare my_datetime DATE ; old_points number ( 9 ) ; my_trans_n
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 715 # Implicit conversion of string literal to
    'char *' is deprecated.
         "declare my_datetime DATE ; old_points number ( 9 ) ; my_trans_n
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 1191 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_datetime DATE ; my_trans_no number ( 9 ) ; BEGIN sel
         ^^^^^^^^^^^^^^^^                                                
Warning 829: "BS_LOGIC.c", line 1814 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_trans_no NUMBER ( 9 ) ; ea_trans_no NUMBER ( 9 ) ; m
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 1829 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "_redeemed , 0 ) + NVL ( points_adjusted , 0 ) + NVL ( points_tr
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 1844 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "ans_no from dual ; insert into event_award_history ( member_no
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 1859 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "_no , datetime_redeem , expiry_date , item_code , merchant_code
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 1874 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "request , datetime_request , transaction_no , event_code , rema
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 2162 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_trans_no NUMBER ( 9 ) ; my_datetime DATE ; my_points
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 2463 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_datetime DATE ; my_trans_no number ( 9 ) ; my_member
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 2478 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "where item_code = my_item_code ; update voucher set status = 'C
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 2986 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_datetime DATE ; my_trans_no number ( 9 ) ; my_old_tr
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3243 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_datetime DATE ; my_member_no char ( 10 ) ; my_cso_id
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3561 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_trans_no NUMBER ( 9 ) ; ea_trans_no NUMBER ( 9 ) ; m
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3576 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "ard_points_balance , 0 ) + NVL ( points_redeemed , 0 ) + NVL (
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3591 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "_points ) ; select ea_transaction_no . nextval into ea_trans_no
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3909 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_trans_no NUMBER ( 9 ) ; ea_trans_no NUMBER ( 9 ) ; m
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 3924 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "points , kf_balance_points from members where member_no = :h_me
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Warning 829: "BS_LOGIC.c", line 4201 # Implicit conversion of string literal
    to 'char *' is deprecated.
         "declare my_trans_no NUMBER ( 9 ) ; my_datetime DATE ; my_event_
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
0
Comment
Question by:PeterKarpov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 7170989
I recommend you do modify your code.

If you have code like this:
char * foo = "Hello World";

You should change it to a const type like the following:
const char * foo = "Hello World";
0
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
ID: 7170995
Pointers initiated by string literial should be constant type.

If you try to modify a variable that is pointing to a string literial, your code can result in undefined behavior.

On some compilers, you will not get any errors, while on other compilers, you'll get an error.

For example, code compile in VC++ Ver 5.0, has no problem with modifying a variable pointing to a string literial.

However, VC++ Ver 6.0, will give you a runtime error with the same code.
0
 
LVL 1

Expert Comment

by:ris
ID: 7174824
if you need to be able to modify the string, you should use this code instead:

char foo[MAX_LENGTH];
strcpy(foo, "string literal");

or better:

char foo[MAX_LENGTH];
strncpy(foo, "string literal", MAX_LENGTH);

or with dynamic allocation:

int nStrMaxLen = 500;
char foo = new char[nStrMaxLen]; //or you could use malloc()
strncpy(foo, "string literal", nStrMaxLen);

-------------

If you don't need to modify the string at all, then you could considering using #define macros instead of const char* variables as in:

#define foo "string literal"

With the advantage that if you never use 'foo' anywhere in your code, then no memory is ever allocated for it, slightly optimizing your executable code.  The compiler's optimizer may be able to do that just as well with a const char* variable though, so it's more of a matter of personal style than anything else.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Axter
ID: 7174872
>>if you need to be able to modify the string, you should >>use this code instead:

Or if he needs to initialize and declare a string that later needs to be modified, he can do the following:

char foo[] = "Hello World";

or

char foo[MAX_LEN] = "Hello World";


The first method has almost the same effect as the following:
char *foo = "Hello World";

The diffrence being, that you are allowed to modify the char foo[] type.
0
 
LVL 11

Expert Comment

by:griessh
ID: 7378414
Dear PeterKarpov

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "Axter"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7420029
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 157
Using Diagnostic tools in VS2015: Unresoved allocations 19 140
How do i run a c++ file? 15 57
find Speed using GPS latitude & longitude 4 152
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question