473,836 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile C Code With A CPP Compiler?

Hey all,

I'm working with some legacy C code and I would like to compile it as
a CPP file.

I get the following error message:

driver.cpp:87: cannot convert `void *' to `GenericStruct *' in
assignment

Reading through the web I've come across vague references to the
'void' issue between C and C++, I don't know C++ well and would
appreciate any pointers or references which might help me out.

Thanks!

entropy
Nov 13 '05
52 6831
"P.J. Plauger" <pj*@dinkumware .com> wrote:
"Micah Cowan" <mi***@cowan.na me> wrote in message news:m3******** ****@localhost. localdomain...
Ridiculous. If you want C++ code, then it's much better to write
C++ code then to try to make C-ish C++ code or C++-ish C
code. When you try to write code that compiles in both, you wind
up using idioms that are considered crappy by knowledgeable
coders of both languages.


Darn, and I've *so* wanted to be considered a knowledgable
coder. Forty years wasted. As I've mentioned before, essentially
all of our C code is written to compile as both Standard C and
Standard C++. We find it pretty readable and our customers have
yet to complain about its crappiness.


Is this hand-written or machine-generated code? Different rules apply to
those, you know. Machine-generated code, for example, doesn't need to be
maintainable - you maintain the source that the machine generated the
code from. Hand-written code must conform to much stricter rules,
because we can trust it less.

Richard
Nov 13 '05 #31
"P.J. Plauger" <pj*@dinkumware .com> wrote:
"Richard Heathfield" <do******@addre ss.co.uk.invali d> wrote in message
news:bl******** **@hercules.bti nternet.com...
int* p = (int*)malloc(n* sizeof(int));
Typical Tisdale nonsense.


Mine too.
Quite apart from the hopelessly daft type dependency inside the malloc, the
spurious cast constitutes unwarranted chumminess with C's sister language.


You mean we should avoid writing anything in C that someone might suspect
would also be good C++?


What a nonsensical reaction! No, we should avoid writing C which is iffy
for no better reason than that it's also legal (but iffy) C++.
All code should either do something good or stop something bad from
happening.


Where does that leave comments?


Comments do something good: they explain code to the maintainer.
Your cast does neither.


But it does reassure the reader that you know what kind of storage
you're trying to allocate.


No, it doesn't. It reassures the reader that you can read declarations.
Well, wow.
And it causes a compile-time diagnostic
if you later change the type of the pointer you're assigning to,
without changing the sizeof to match.
That's better, more legibly, more concisely and more dependably done
like this:

int *p = malloc(n * sizeof *p);

(Note also that I moved the pointer in the type. The original was
confusing in that respect, also; int* p,q; does _not_ declare two
pointers.)
Anything that improves readability at no cost in code size
or execution time has to be salutary, in my book.


Yup. Pity that casting malloc() makes the code more complex, larger
_and_ more brittle.

Richard
Nov 13 '05 #32
[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]

Richard Bos wrote:
"P.J. Plauger" <pj*@dinkumware .com> wrote:
"Richard Heathfield" <do******@addre ss.co.uk.invali d> wrote in message
news:bl******** **@hercules.bti nternet.com...
> > int* p = (int*)malloc(n* sizeof(int));
>
> Typical Tisdale nonsense.
Mine too.
> Quite apart from the hopelessly daft type dependency inside the malloc,
> the spurious cast constitutes unwarranted chumminess with C's sister
> language.


You mean we should avoid writing anything in C that someone might suspect
would also be good C++?


What a nonsensical reaction! No, we should avoid writing C which is iffy
for no better reason than that it's also legal (but iffy) C++.


I agree with all but the first four words. I think we should respect the
fact that P J Plauger is an expert on the C language, even if we happen to
disagree with him on this issue.
> All code should either do something good or stop something bad from
> happening.


Where does that leave comments?


Comments do something good: they explain code to the maintainer.


Right.
> Your cast does neither.
But it does reassure the reader that you know what kind of storage
you're trying to allocate.
That isn't the purpose of casts. In any event, as Richard Bos rightly points
out below, the construct:

T *p = malloc(n * sizeof *p);

is always[1] correct for any object type T, so the reader doesn't need
reassuring.

No, it doesn't. It reassures the reader that you can read declarations.
Well, wow.


If we can take the heat out of this, we might get a bit more light.
And it causes a compile-time diagnostic
if you later change the type of the pointer you're assigning to,
without changing the sizeof to match.


That's better, more legibly, more concisely and more dependably done
like this:

int *p = malloc(n * sizeof *p);

(Note also that I moved the pointer in the type. The original was
confusing in that respect, also; int* p,q; does _not_ declare two
pointers.)


Not having the original in front of me, I can't tell what you mean for
certain, but if the original layout was: int* p = malloc..., I don't think
it's a big deal, especially if declarations are kept one to a line (which
is my own preference).
Anything that improves readability at no cost in code size
or execution time has to be salutary, in my book.


Yup. Pity that casting malloc() makes the code more complex, larger
_and_ more brittle.


Right. The key point, IMHO, is readability, and adding spurious casts
impairs readability. As for the whole issue of programming in a subset of C
common to C and C++, I consider this an utterly unnecessary restriction, as
pointless as programming in the common subset of C and COBOL, or C and
BASIC, or C and Pascal. Clearly, Mr Plauger's mileage varies, and I'm not
about to suggest that he changes his business's development strategy on the
basis of a newsgroup discussion! Nevertheless, I can't see myself advising
anyone to adopt that strategy any time soon.

[1] Never[2] say "always".
[2] Or "never".

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #33
Richard Heathfield wrote:

[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]


I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.


Brian Rodenborn
Nov 13 '05 #34
Default User <fi********@com pany.com> scribbled the following:
Richard Heathfield wrote:
[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]
I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.


The same happened to me. What's with this thing? What do news servers
have against Plauger? Perhaps we should make a poll about who can see
his messages and who can't.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Hasta la Vista, Abie!"
- Bart Simpson
Nov 13 '05 #35
In article <bl**********@o ravannahka.hels inki.fi>,
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Default User <fi********@com pany.com> scribbled the following:
Richard Heathfield wrote:
[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]
I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.


The same happened to me. What's with this thing? What do news servers
have against Plauger?


Perhaps something his newsreader or server is doing is producing malformed
headers that some servers are dropping?

trn is displaying the followups to his posts as orphaned articles, and
not the normal "I know there should be an article here, but I can't find
it" entry in the thread display[1], which leads me to suspect something
wrong with the References header as a first guess.

Can anybody who can see his posts comment on this?

Perhaps we should make a poll about who can see
his messages and who can't.
I can't.
dave

[1] trn normally shows you something like this at the top of an article:
(1)+-(1)--(1)
\-(1)+-(1)--(2)
\-[1]
where the various bits of the display give information about
references, subject lines, and whether an article has been read.
Normally for a nonexistent article whose existence is inferred from
other clues (such as a Message-ID appearing in a followup's References
header) it will display the article without the number: "( )", while
the followups to Plauger's posts appear in a new left-hand entry,
indicating a common subject line but no known parents.

--
Dave Vandervies dj******@csclub .uwaterloo.ca My goodness, how dry the British sense of humor is.

It's to compensate for our traditional weather.
--Dann Corbit and Chris Dollin in comp.lang.c
Nov 13 '05 #36
"Default User" <fi********@com pany.com> wrote in message
news:3F******** *******@company .com...
Richard Heathfield wrote:

[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]


I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.


I don't see them either. Perhaps a major trunk is down,
and only servers in a paritcular physical region are getting
them? I'm no networking expert, just a thought.

-Mike
Nov 13 '05 #37
On Tue, 07 Oct 2003 20:11:28 +0000, Dave Vandervies wrote:
In article <bl**********@o ravannahka.hels inki.fi>,
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Default User <fi********@com pany.com> scribbled the following:
Richard Heathfield wrote:
[PJP's article didn't show up on my server yet, hence the (partial)
piggy-backing.]

I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.


The same happened to me. What's with this thing? What do news servers
have against Plauger?


Perhaps something his newsreader or server is doing is producing malformed
headers that some servers are dropping?

trn is displaying the followups to his posts as orphaned articles, and
not the normal "I know there should be an article here, but I can't find
it" entry in the thread display[1], which leads me to suspect something
wrong with the References header as a first guess.

Can anybody who can see his posts comment on this?


I can't comment, but here are some headers:

Date: Tue, 7 Oct 2003 10:21:07 -0400
From: "P.J. Plauger" <pj*@dinkumware .com>
Lines: 50
Message-ID: <3f82cbd4$0$758 7$afc38c87@>
NNTP-Posting-Host: 63.102.52.148
Newsgroups: comp.lang.c
Path: sn-us!sn-xit-04!sn-xit-06!sn-xit-08!supernews.co m!news-out.visi.com!pe tbe.visi.com!as h.uu.net!spool. news.uu.net!not-for-mail
References: <90************ **************@ posting.google. com> <EJ************ *****@newsread4 .news.pas.earth link.net> <90************ **************@ posting.google. com> <oY************ ******@newsread 3.news.pas.eart hlink.net> <90************ **************@ posting.google. com> <3F************ **@jpl.nasa.gov > <bl**********@h ercules.btinter net.com>
Subject: Re: [OT] Compile C Code With A CPP Compiler?
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-Priority: 3
X-Trace: 1065536468 7587 63.102.52.148
Xref: sn-us comp.lang.c:670 030
MIME-Version: 1.0
Content-Type: text/plain

Nov 13 '05 #38
Mike Wahler wrote:
Default User wrote:
Richard Heathfield wrote:

I haven't seen ANY of his messages, but lots of replies to them.
Not sure what's up with that.

I don't see them either.


Did you check your killfile?

Nov 13 '05 #39
[Posted and mailed to pj*@dinkumware. com]

In article <pa************ *************** *@yahoo.com>,
Sheldon Simms <sh**********@y ahoo.com> wrote:
On Tue, 07 Oct 2003 20:11:28 +0000, Dave Vandervies wrote:
In article <bl**********@o ravannahka.hels inki.fi>,
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Default User <fi********@com pany.com> scribbled the following:
Richard Heathfield wrote:
> [PJP's article didn't show up on my server yet, hence the (partial)
> piggy-backing.]

I haven't seen ANY of his messages, but lots of replies to them. Not
sure what's up with that.

The same happened to me. What's with this thing? What do news servers
have against Plauger?
Perhaps something his newsreader or server is doing is producing malformed
headers that some servers are dropping?

trn is displaying the followups to his posts as orphaned articles, and
not the normal "I know there should be an article here, but I can't find
it" entry in the thread display[1], which leads me to suspect something
wrong with the References header as a first guess.

Can anybody who can see his posts comment on this?


I can't comment, but here are some headers:

Date: Tue, 7 Oct 2003 10:21:07 -0400
From: "P.J. Plauger" <pj*@dinkumware .com>
Lines: 50
Message-ID: <3f82cbd4$0$758 7$afc38c87@>

^^
<snip rest of headers>

That Message-ID isn't in the normal form <unique-identifier@host > - it's
missing the "host" part. I'm not sure whether it's actually considered
a malformed Message-ID or whether the servers that are dropping it are
broken[1], but in any case it seems to be rather antisocial behavior on
the part of whatever is assigning them.

In the time-honored usenet tradition of making unwarrantedly definite
statements from vague or nonexistent evidence, I'm going to suggest that
perhaps the host that's being used to post the articles doesn't have a
hostname configured and that's what's breaking the Message-ID.

'Tmight be a good idea to find the person responsible and arrange for
a hostname to be set.
dave

[1] The best I could come up with is from section 2.1.7 of RFC 850:
--------
Message ID's have the syntax

"<" "string not containing blank or >" ">"

In order to conform to RFC 822, the Message-ID must have
the format

"<" "unique" "@" "full domain name" ">"

where "full domain name" is the full name of the host at
which the article entered the network, including a domain
that host is in [...]
--------
Without reading anything beyond the immediate context, it's not clear
whether conformance to RFC822 (which requires the unique@host form)
is a requirement.

--
Dave Vandervies dj******@csclub .uwaterloo.ca My goodness, how dry the British sense of humor is.

It's to compensate for our traditional weather.
--Dann Corbit and Chris Dollin in comp.lang.c
Nov 13 '05 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2632
by: Jordan Willms | last post by:
My xsl stylesheet is as simple as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:ims="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns="http://ltsc.ieee.org/xsd/LOMv1p0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/> <!-- rename ims datetime tags to IEEE dateTime tags --> <xsl:template match="ims:datetime">
6
3340
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for my particular application. One of the advantages is that the _compiler_ can force inner matrix dimensions used in multiplication to agree. A _complie-time_ error will be triggered if you write A * B and the number of coluns in A does not equal the...
17
3139
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We know the address of the variable until run-time. During the compilation, how can we access to the...
5
3342
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new rightType;
5
3825
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace ) Person.xsd includes Common-Naming.xsd ( anonimous schemas ) Common-Naming.xsd includes common.xsd ( both are anonimous schemas ) Compilation of Resident.xsd raise the following exception: "System.Xml.Schema.XmlSchemaException: The attribute 'oid'...
10
4479
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
2
4651
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a potential issue. For example, in the assembly I would like to add a constraint that states a particular property member of the class can not be equal to one other property. In standard coding I can throw an exception during run-time, but I would rather...
4
8987
by: John Smith | last post by:
Hi I'm porting some C++ code to new platforms and have some 1-byte aligned structures which need a specific size. Since datatypes can vary on different platforms (which I found out the hard way since longs are not the same size on win64 and linux x64) I would like to do a check at compile time to make sure things are correct. This will ease future work. Is it possible to do something like the following at preprocessing stage:
15
4862
by: steve yee | last post by:
i want to detect if the compile is 32 bits or 64 bits in the source code itself. so different code are compiled respectively. how to do this?
12
2768
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
0
9818
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10843
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10589
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4015
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.