Link to home
Start Free TrialLog in
Avatar of PeterKarpov
PeterKarpov

asked on

"Implicit conversion of string literal" during compilation

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_
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                    
Avatar of Axter
Axter
Flag of United States of America image

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";
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ris
ris

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.
>>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.
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
Force accepted

** Mindphaser - Community Support Moderator **