dialect of c++ that includes ansi C

P

Phlip

I use a c++ front end to compile C code, I run into problems when
void* pointers are implicitly converted. Is there a fix to this kind
of issue?

One can write C code that is also "C-style" C++ code. This requires avoiding
C's known abuses, such as converting from void* too easily, and requires
adding C-style typecasts here and there. So "C-style" is a _programmer_
dialect that fits C code into C++ compilers...

IIRC:

char * foo = (char*)malloc(42);

C++ requires the typecast and C permits it.
 
V

vcciubot

Hi all,

I use a c++ front end to compile C code, I run into problems when
void* pointers are implicitly converted. Is there a fix to this kind
of issue? Are there c++ dialects that are supersets of C?

thanks in advance,
vlad
 
D

Default User

Hi all,

I use a c++ front end to compile C code, I run into problems when
void* pointers are implicitly converted. Is there a fix to this kind
of issue?

Yeah, don't do that. Use C compilers for C code, link the results.
Are there c++ dialects that are supersets of C?

If there are, they're off-topic here. The standard requires a
diagnostic for the situation you mention.





Brian
 
D

Default User

Phlip said:
One can write C code that is also "C-style" C++ code. This requires
avoiding C's known abuses, such as converting from void* too easily,

Nonsensical response. It's an "abuse" only in your mind, and it's
non-responsive to the OP's question.





Brian
 
W

Walter Bright

I use a c++ front end to compile C code, I run into problems when
void* pointers are implicitly converted. Is there a fix to this kind
of issue? Are there c++ dialects that are supersets of C?

The behavior you see is standard conforming behavior. Programming in a
non-standard dialect, without really compelling reasons to, is sure to
cause you (and your colleagues) nuisance problems in the future far out
of proportion to just sticking with standard behavior.
 
B

Barry

Hi all,

I use a c++ front end to compile C code, I run into problems when
void* pointers are implicitly converted. Is there a fix to this kind
of issue? Are there c++ dialects that are supersets of C?

As stated else-thread, don't.

But if you're creating C-style API wrappers for you code, then try this

typedef struct
{
void* pointer;
} XXX;

then every XXX is a distinct type.
 
J

Justin.SpahrSummers

One can write C code that is also "C-style" C++ code. This requires avoiding
C's known abuses, such as converting from void* too easily, and requires
adding C-style typecasts here and there. So "C-style" is a _programmer_
dialect that fits C code into C++ compilers...

IIRC:

char * foo = (char*)malloc(42);

C++ requires the typecast and C permits it.

Except that doing such a typecast in C is bad practice because it can
hide a missing declaration of malloc().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top