Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting Invalid conversion from const char* to char* on gcc 4.4.1

935 views
Skip to first unread message

Raj

unread,
Aug 2, 2010, 3:48:41 AM8/2/10
to
Hi,

I am trying to build a code on gcc 4.4.1, but getting an error :
"Invalid conversion from const char* to char* on gcc 4.4.1"

The code has been successfully build against gcc 4.3.2.

I feel it maybe due to warning turned errors on upgraded version of
gcc !!!

I want to know what way can I build the code. Can I downgrade the
version? If yes, please
suggest the optimal way. I am using Ubuntu-9.10.

Please suggest if any other way.

Note : I can't make changes in the source code.

Thnx,
Raju

Andrew Haley

unread,
Aug 2, 2010, 5:09:55 AM8/2/10
to
Raj <raaju....@gmail.com> wrote:

> I am trying to build a code on gcc 4.4.1, but getting an error :
> "Invalid conversion from const char* to char* on gcc 4.4.1"
>
> The code has been successfully build against gcc 4.3.2.
>
> I feel it maybe due to warning turned errors on upgraded version of
> gcc !!!
>
> I want to know what way can I build the code. Can I downgrade the
> version? If yes, please
> suggest the optimal way. I am using Ubuntu-9.10.

We use to have -fwriteable-strings for this, but it's obsolete now.

> Please suggest if any other way.
>
> Note : I can't make changes in the source code.

What does this mean? Some boss says you can't? The code is
incorrect: it would be irresponsible not to fix it.

Andrew.

Raj

unread,
Aug 2, 2010, 6:43:48 AM8/2/10
to
On Aug 2, 2:09 pm, Andrew Haley <andre...@littlepinkcloud.invalid>
wrote:

Hi Andrew,

Thanks for the quick response.

Actually I am not authorized to make any changes in the source code.

Since the code is working fine with gcc 4.3.2, I have two options :
either I re-install my system with previous version of

ubuntu, which will have gcc version 4.3.2, else I downgrade my gcc
version to meet the requirement.

I just want to give a try to downgrade the version, since re-
installing may take some time. Please suggest how should I go ahead. I
tried many links but did not get much.

Thanx,
Raju.

Thomas Maeder

unread,
Aug 2, 2010, 12:40:25 PM8/2/10
to
Raj <raaju....@gmail.com> writes:

> Actually I am not authorized to make any changes in the source code.

This seems a serious case of "either change your organization or
change your organization".


> Since the code is working fine with gcc 4.3.2, I have two options :
> either I re-install my system with previous version of ubuntu, which
> will have gcc version 4.3.2, else I downgrade my gcc version to meet
> the requirement.

Shooting the messenger is rarely a good idea.

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Keith Thompson

unread,
Aug 2, 2010, 6:23:24 PM8/2/10
to
Raj <raaju....@gmail.com> writes:
> I am trying to build a code on gcc 4.4.1, but getting an error :
> "Invalid conversion from const char* to char* on gcc 4.4.1"
>
> The code has been successfully build against gcc 4.3.2.

Under gcc 4.3.2, it probably produced a warning:

warning: initialization discards qualifiers from pointer target type

which was apparently ignored. That was the first mistake.

> I feel it maybe due to warning turned errors on upgraded version of
> gcc !!!

Probably, but it would be more accurate to say that it's due to
an error in the code which the more recent gcc does a better job
of diagnosing.

> I want to know what way can I build the code. Can I downgrade the
> version? If yes, please
> suggest the optimal way. I am using Ubuntu-9.10.
>
> Please suggest if any other way.
>
> Note : I can't make changes in the source code.

I'm partially speculating, since you haven't shown us the code
that triggers the error messages. Here's a likely candidate:

void foo(void) {
const char *c = "hello";
char *s = c;
}

The initialization of s violates a constraint; it's perfectly
reasonable for gcc to reject it.

Whatever else you do, you should discuss this with whoever told
you that you're not allowed to make changes in the source code.
The current source code needs to be fixed, if not by you then by
someone else.

Once you've set the ball rolling on that, *then* it's reasonable
to think about getting the current broken code to compile.

I'm sure it's possible to install an older version of gcc on Ubuntu,
but I'm not sure of the best way to go about it. If nothing else,
you could compile it from source, but that's non-trivial. You'll get
better advice on this in an Ubuntu forum. A Google search for
"Ubuntu downgrade gcc" gives some results that might be useful.

You should also think about whether it's acceptable to clobber the
current gcc on your system by installing an older one.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson

unread,
Aug 4, 2010, 2:50:36 PM8/4/10
to

Using gcc 4.4.3 on Ubuntu 10.04, the following:

void foo(void) {
const char *c = "hello";

char *p = c;
}

gives me:

c.c: In function ‘foo’:
c.c:3: warning: initialization discards qualifiers from pointer target type

I get a similar warning with an assignment rather than an initializer.

Is gcc 4.4.1 pickier than 4.4.3 in this case?

If you can post a small code sample that triggers the "Invalid
conversion from const char* to char*" message, we're more likely
to be able to help.

(And again, the real solution is to fix the code; if you can't do it
yourself, talk to someone who can.)

Jan Seiffert

unread,
Aug 4, 2010, 9:43:56 PM8/4/10
to
Keith Thompson schrieb:
[snip]

> Using gcc 4.4.3 on Ubuntu 10.04, the following:
>
> void foo(void) {
> const char *c = "hello";
> char *p = c;
> }
>
> gives me:
>
> c.c: In function ‘foo’:
> c.c:3: warning: initialization discards qualifiers from pointer target type
>
> I get a similar warning with an assignment rather than an initializer.
>
> Is gcc 4.4.1 pickier than 4.4.3 in this case?
>
> If you can post a small code sample that triggers the "Invalid
> conversion from const char* to char*" message, we're more likely
> to be able to help.
>

I guess, from the wording of the Error message, that it is C++ code. And in C++
is the const not as lax as in C.
G++ gets stricter and stricter (more language std. compliant) what C++
abomination are accepted from version to version. Which is an effect of C++
being so complex, you can not even implement it without errors.

I think the 4.4 trend is to throw:
"Warning: converison from std:string to char * is deprecated"
or something like that (and makes fun with -Werror). This will bring the distro
guys sleepless nights in fixing all the old C++ code.

Say no to C++

> (And again, the real solution is to fix the code; if you can't do it
> yourself, talk to someone who can.)
>

That is the ultimate goal.
If there is not a broken API which basically can not be fixed (they build
something like strchr, takes a const char *, returns a char * which is in this
const char *, so you have to cast the const away. And you can shoot yourself in
the foot with this, thats why C++ sees the const much stricter)

Greetings
Jan

--
Every program in development at MIT expands until it can read mail.

Raj

unread,
Aug 5, 2010, 9:34:37 AM8/5/10
to
> Every program in development at MIT expands until it can read mail.- Hide quoted text -
>
> - Show quoted text -

Thank you everyone for all the information :)

I understand that the source code needs to be modified and I have
requested regarding that !!!

In the meantime, I have done the following changes and now I am able
to build the code on my system.

I installed gcc 4.3.4 and g++ 4.3.4 and created a link (ln -s /usr/bin/
gcc-4.3.4 /usr/bin/gcc) for both gcc and g++.

The code builds fine now.

Thanx,
Raju.


0 new messages