By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Can't decipher compiler error

P: n/a
The compiler(gcc) gives me this error

faxGettyApp.c++:596: ANSI C++ forbids implicit conversion from `void *' in
assignment
make[3]: *** [faxGettyApp.o] Error 1

on this code

void
faxGettyApp::setEnvVar(char* var, char* val)
{
char * v;
596 v = malloc( strlen(var) + strlen(val) + 2 );
if ( v == NULL )
traceServer("runGetty: setEnvVar: cannot malloc" );
else
{
sprintf( v, "%s=%s", var, val );
if ( putenv( v ) != 0 )
traceServer("runGetty: putenv: putenv failed" );
}
}
this function is called by:

setenv("ABCDEF", abcd)

where "abcd" is of type fxStr
where fxStr is special class for strings defined in the program.

What does this error mean?
Thanks

George
--
#
#...
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"George Bell" <ma*************@netscape.net> wrote in message
news:vG7pc.1256$65.768@lakeread06...
The compiler(gcc) gives me this error

faxGettyApp.c++:596: ANSI C++ forbids implicit conversion from `void *' in
assignment
make[3]: *** [faxGettyApp.o] Error 1

on this code

void
faxGettyApp::setEnvVar(char* var, char* val)
{
char * v;
596 v = malloc( strlen(var) + strlen(val) + 2 );
if ( v == NULL )
traceServer("runGetty: setEnvVar: cannot malloc" );
else
{
sprintf( v, "%s=%s", var, val );
if ( putenv( v ) != 0 )
traceServer("runGetty: putenv: putenv failed" );
}
}
this function is called by:

setenv("ABCDEF", abcd)

where "abcd" is of type fxStr
where fxStr is special class for strings defined in the program.

What does this error mean?
Thanks

George


Guess what, it means you cannot implicitly convert from void* (to char*).

char * v;
v = malloc( strlen(var) + strlen(val) + 2 );

v is type char*, malloc returns type void*. In C++ it is not legal to
convert from void* to char*. It is legal in C, maybe this is what is
confusing you, the code you've posted looks like C code not C++ code.
Perhaps you should try a C compiler instead.

If you want to carry on with a C++ compiler then you are going to have to
add a cast

v = (char*)malloc( strlen(var) + strlen(val) + 2 );

john
Jul 22 '05 #2

P: n/a
George Bell wrote:
The compiler(gcc) gives me this error

faxGettyApp.c++:596: ANSI C++ forbids implicit conversion from `void *' in
assignment
make[3]: *** [faxGettyApp.o] Error 1
There is no implicit conversion from 'void*' to 'char*' in C++. If your
code depends on such conversion, you have to do it explicitly.
on this code

void
faxGettyApp::setEnvVar(char* var, char* val)
{
char * v;
596 v = malloc( strlen(var) + strlen(val) + 2 );
if ( v == NULL )
traceServer("runGetty: setEnvVar: cannot malloc" );
else
{
sprintf( v, "%s=%s", var, val );
if ( putenv( v ) != 0 )
traceServer("runGetty: putenv: putenv failed" );
}
}


--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.