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

dialect of c++ that includes ansi C

P: n/a
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

Sep 6 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
vc******@gmail.com wrote:
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
Sep 6 '07 #2

P: n/a
vc******@gmail.com wrote:
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.

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
Sep 6 '07 #3

P: n/a
Phlip wrote:
vc******@gmail.com wrote:
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,
Nonsensical response. It's an "abuse" only in your mind, and it's
non-responsive to the OP's question.

Brian
Sep 6 '07 #4

P: n/a
vc******@gmail.com wrote:
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.

-------------
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
http://www.astoriaseminar.com Extraordinary C++
Sep 7 '07 #5

P: n/a
vc******@gmail.com wrote:
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.

--
Thanks
Barry
Sep 7 '07 #6

P: n/a
On Sep 6, 4:27 pm, Phlip <phlip2...@gmail.comwrote:
vcciu...@gmail.com wrote:
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.
Except that doing such a typecast in C is bad practice because it can
hide a missing declaration of malloc().

Sep 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.