Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"Implicit conversion of string literal" during compilation

Posted on 2002-07-22
6
Medium Priority
?
719 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 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

721 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