473,889 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# vs. C++

cj
I don't want to start a war but why would I choose one over the other?
First and foremost I need to keep in mind marketability of the skill and
the future of the language.

I'm getting the feeling I'll be moving from VB to one or the other. I
have some say on which but perhaps not the final decision. I have used
C and C++ a little bit years ago. I have no experience in C#. I don't
expect it to be that difficult but I hate remembering the idiosyncrasies
of too many languages so I'd like to pick one C# or C++ and make the
right choice.
Jun 27 '08
151 4321
Andre Kaufmann wrote:
Arne Vajhøj wrote:
>[...]
>>Boost is a good, cool library - sure. But these libraries get somewhat
bloated, because of all the template stuff and compilation slows down
more and more.
Compilation speed is usually not important.

Why ? For RAD tools it's IMHO essential and if 1000 developers wait
daily an hour for compilation they are loosing simply 1000 hours of
development time, besides the energy wasted.
You can always throw processing power at this problem
(www.xoreax.com). This worked great for a company I used
to work for and turned 60mins into 12mins.
OTOH, you cannot throw processing power at debugging. So
easily creating correct code is more important than fast
compilation.
[...]
Andre
Schobi
Jun 27 '08 #91
Daniel James wrote:
[...]
The fprintf and sprintf functions will always be slow as they have to
parse the formatting string each time as well as producing output, so I
wouldn't expect them to do well. I'd expect the iostreams version to be
a good bit quicker [...]
Usually iostreams are implemented using the 'printf()' family,
so it's very unlikely they're faster. It's sad, because with all
the type info known at compile-time streams ought to be faster
than 'printf()', but that potential was never used. Dietmar Kühl
once had an implementation that didn't do this and was regarded
fast, but for some reason it never took off.
[...]
Daniel.
Schobi
Jun 27 '08 #92
Hendrik Schober wrote:
You can always throw processing power at this problem
(www.xoreax.com). This worked great for a company I used
to work for and turned 60mins into 12mins.
Still a long time. <g>

--
Rudy Velthuis http://rvelthuis.de

"Ignorance simplifies ANY problem." -- R. Lucke
Jun 27 '08 #93
Rudy Velthuis <ne********@rve lthuis.dewrote:
Hendrik Schober wrote:
> You can always throw processing power at this problem
(www.xoreax.com). This worked great for a company I used
to work for and turned 60mins into 12mins.

Still a long time. <g>
Yes, but this was several MLoC. And usually you don't
have to compile /everything/ during writing/fixing
code.

Schobi

--
Sp******@gmx.de is never read
I'm HSchober at gmx dot de
"I guess at some point idealism meets human nature and
explodes." Daniel Orner
Jun 27 '08 #94
In article news:<MP******* **************@ msnews.microsof t.com>, Jon
Skeet wrote:
I didn't, actually. Sorry about that - it does sort of make a nonsense
of the sentence that I *did* quote though.
Not really. First bit says the JVM is only meant to be for Java, second
bit says that hasn't stopped people using it for other languages
(without Sun's blessing, at least in the earlier cases).
And yes, I agree that it would be pretty hard to target the JVM with C
or C++.
Yeah ... Sun would probably say that the JVM has no opcodes that can be
used to support pointer arithmetic (a) because Java doesn't need them,
and (b) because they're potentially unsafe; but I bet they regarded the
fact that that meant you couldn't target it from C or C++ as an added
bonus.

No, I don't suppose they went out of their way to make it impossible to
implement C or C++ to target the JVM /per se/, but I do think they saw
pointer manipulations as a bad thing and deliberately left them out of
the instruction set of the JVM so people couldn't use them -- after all:
Java doesn't need them, and who would be silly enough to use anything
else.

There's a big difference in mindset, though, between what Sun did with
Java (we've just reinvented p-code and it's just for our new language
called 'Java' -- so we've called it the "Java Virtual Machine") and what
Microsoft did with .NET (we've just reinvented p-code (again) -- and we
want it to be able to run any language you like, and we want third
parties to port their languages to it ... oh, and we've just developed a
new language called C# that will target this and nothing else, but don't
you worry about that).

Now, admittedly, MS needed to shout all they could about any advantages
offered by the CLI over the JVM, so that they could attract attention
away from the JVM -- which was becoming an established standard -- so
they had some interest in gathering as much 3rd-party support as
possible in any way they could ... but it looks like a very different
attitude to mixed-language programming to me!

Does anyone actually use Eiffel.NET, BTW? I haven't heads anything about
it since it was heralded as one of the first examples of a third-party
language targeting the CLI, way back when.
But that's the point - if their project *does* use Python or Ruby
already, or if they've already got a lot of code in Java that they
want to use later with Python or Ruby - then Jython and JRuby are
a natural fit.
Yes, I agree. Sorry, I think you missed my point -- I should probably
have said "but" or "whereas" or something in there -- Most of the
languages mentioned are just research toys, BUT (I went on to say)
Jython and Groovy (and JRuby, if you say so, I know less about that) do
have real-world uses.

I hadn't seen Scala before ... it looks very Java-like (perhaps
unsurprisingly) and I'm not sure quite what makes it different, on a
first glance. I'll obviously have to read further.
I haven't replied to your other posts about LINQ, by the way, but I
think you'd be wise to look into it further ...
I certainly don't know much about it ... usually it's been discussed as
a way to bind databases to C# code (and it all seemed very reminiscent
of the hype that ODBC got when it was new). I'll look further, thanks
for the "heads up".

Cheers,
Daniel.
Jun 27 '08 #95
In article news:<uI******* *******@TK2MSFT NGP02.phx.gbl>, Andre Kaufmann
wrote:
I don't know all the internals. AFAIK Cosmos includes a compiler,
which
translates the IL code generated by C# to x86 code.

No basically it is C# translated directly to native code, with some
extensions to let C# interact directly with the CPU.
OK, that's interesting. It's C# but not C#.NET.
What are COMPILER X and COMPILER Y?

Windows C++ compilers, I don't think that the vendors are quite
interesting ...
I had it half in mind to repeat your tests and try to see where the C++
versions were taking their time ... I obviously can't do that very
meaningfully if I can't know that I'm using the same tools.

I guess at least the C# compiler must have been a Microsoft one <smile>
Close doesn't matter and yes all produce the identical output.
Close *does* matter ... especially if the output is buffered up to that
point and only written to disk on the close call. It could be that all
the real work actually takes place outside the timing loop in some of
your tests.
The fprintf and sprintf functions will always be slow as they have
to parse the formatting string each time as well as producing
output, so I ...

The printf functions are commonly faster, because they don't have that
much overhead. IIRC correctly IOStreams (e.g. the ones shipped with
VC9.0) are using sprintf internally for formatting.
I haven't got a VC9 installation handy ... but in VC8 the iostream
implementation certainly doesn't use sprintf. That would be a very
suboptimal implementation when you already know the type of the value
that's to be formatted. The overhead of printf is quite considerable as
the "%d" (or whatever) has to be interpreted on every call.

There is certainly some overhead associated with streams, too, but it
should be less than that with the ?printf functions, except in a very
naive implementation.

You're right that localization imposes some overhead with streams -- but
not for printing integers.
You could try another benchmark with boost::format -- I bet that
would be slower than any of them.

I think it was quite fast.
boost::format does very similar processing to that done by sprintf. It
makes use of the actual type of its arguments rather than taking that
from the format string, but still had to parse the string for layout,
etc. It's usually very slow.

It also has surprising results in some cases -- if you use a char
variable as an 8-bit integer and try to print it using

boost::format( "%d" ) % charvar

boost::format takes the type (char) from the variable and ignores the
type implied by the %d, so you get a character rather than a number. The
only way to get the result you wanted is to cast the variable to an int
(yuk).

[on macros and compilation]
If the build system were smarter it could track that and avoid
recompiling header information that had already been compiled
with the same settings.

Therefore it must have an overview over the whole code must
distinguish different header files with the same name etc. I think
modules will be a better solution.
I agree entirely that modules will be a better solution ... but I don't
think that means that we shouldn't also try to improve tool support for
efficient compilation of today's sourcecode. There are millions and
millions of lines of C++ code in use today, and that body of code won't
magically be converted to use modules one rainy day in (say) 2015 when
compilers start to support them!

[on "Macros are useful too"]
I know and agree. I use them too. But they could have been restricted
to have an effect on one single header file or must be globally
defined.
That wouldn't be compatible with C. In particular it wouldn't be
compatible with the way that C (and C++) allows you to redefine the
NDEBUG macro and include assert.h repeatedly to turn ASSERT macros on
and off throughout a compilation unit. That's a very widespread usage in
some codebases, and restricting the use of macros would break it.

(This sort of code also makes it very hard to write the sort of 'smart'
compilation system that I was talking about ... but that doesn't mean
that it's not worth trying!)
A - O.k. you mean the "template magic" allows C++ to implement
delegates as a library, while you can't in C#, because generics
aren't that flexible enough.
That's kinda what I've been saying all along, yes.
Besides I think templates could be implemented in any
other language too, why should it proof the power of C++ ?
(doesn't mean that I don't like them).
They *could*, but they haven't been. If you were to add a
metaprogramming facility to C# it wouldn't be the C# that we know today.

OTOH if you were to design a metaprogramming facility to add to C# the
resulting language might be a bit nicer to use than C++ is now ... using
C++ templates for metaprogramming (rather than just for implementing
generics) is a bit of a hack -- but it's a very powerful hack, and the
fact that it has been used so much shows how much people want to do this
sort of thing.

I'm not suggesting that C++ is the best language imaginable, just that
it is the best language available today for solving most of the
programming problems with which I find myself faced.
... the .NET framework has Generics. They aren't that powerful as
templates, but on the other side you have the possibility to export
generic lists to other languages.
The implementation of templates in C++/CLI is not provided by the
CLI, but by the C++ compiler. Templates are therefore not visible
to other NET languages.

Yes. Besides security concerns and loosing the strong typing of
Generics, why shouldn't templates been implemented in other languages
too ?
It's not that template couldn't be implemented by other languages, just
that -- at present -- they aren't.

Even if they were I'm not sure that you would be able to achieve
inter-language compatibility with templates, as (in C++, at least) they
are source-code abstractions, and you need a C++ compiler to make use of
them.

Maybe if someone were to come up with a standard for some sort of
meta-code representation then different languages would be able to share
template representations that had been compiled (or part-compiled) down
to that meta-code. The "export" feature in C++ does something along
those lines, but AIUI the intermediate form is still largely C++.
The slides are here:
http://accu.org/content/conf2008/Ale...functional.pdf

Thanks, I'll have a look at it.
I said Andrei had been talking about a mixture of C++ and functional
programming, didn't I? Well, it's D not C++. Still interesting, though.

Cheers,
Daniel.


Jun 27 '08 #96
In article news:<ut******* *******@TK2MSFT NGP06.phx.gbl>, Hendrik
Schober wrote:
Usually iostreams are implemented using the 'printf()' family,
That's obviously an easy-but-naive implementation, I'd hope that as C++
continued to mature quick hacks like that would disappear.

Certainly the current Visual C++ (Dinkumware) runtime doesn't seem to
use sprintf.

Cheers,
Daniel.
Jun 27 '08 #97
On Jun 27, 11:56*am, Daniel James <wastebas...@no spam.aaisp.org>
wrote:
Skeet wrote:
I didn't, actually. Sorry about that - it does sort of make a nonsense
of the sentence that I *did* quote though.

Not really. First bit says the JVM is only meant to be for Java, second
bit says that hasn't stopped people using it for other languages
(without Sun's blessing, at least in the earlier cases).
I think we'll have to agree to disagree about the wording that started
this subthread then. To me, Java *is* an "intermedia te code engine
targeted by more
than one source language". It just isn't an intermediate code engine
*designed* to be targeted by more than one source language.
And yes, I agree that it would be pretty hard to target the JVM with C
or C++.

Yeah ... Sun would probably say that the JVM has no opcodes that can be
used to support pointer arithmetic (a) because Java doesn't need them,
and (b) because they're potentially unsafe; but I bet they regarded the
fact that that meant you couldn't target it from C or C++ as an added
bonus.
Not sure. I strongly suspect that treating Sun as a single entity
doesn't really work here. Different employees of Sun are likely to
have different attitudes.

<snip>
There's a big difference in mindset, though, between what Sun did with
Java (we've just reinvented p-code and it's just for our new language
called 'Java' -- so we've called it the "Java Virtual Machine") and what
Microsoft did with .NET (we've just reinvented p-code (again) -- and we
want it to be able to run any language you like, and we want third
parties to port their languages to it ... oh, and we've just developed a
new language called C# that will target this and nothing else, but don't
you worry about that).
Agreed, although I don't think MS ever claimed that they want you to
be able to run "any language you like" - it needs to have a certain
degree of similarity to the underlying platform. (Some people have
criticised it for precisely this reason, in fact.)

<snip>
Does anyone actually use Eiffel.NET, BTW? I haven't heads anything about
it since it was heralded as one of the first examples of a third-party
language targeting the CLI, way back when.
I haven't heard of much use, but that's a good example of where the
platform gets in the way of the language. From what I remember,
multiple inheritance in Eiffel.NET is a bit of a kludge with various
limitations. In other words, .NET doesn't have the same set of
limitations as Java when it comes to porting languages to it, but
there certainly *are* limitations.
But that's the point - if their project *does* use Python or Ruby
already, or if they've already got a lot of code in Java that they
want to use later with Python or Ruby - then Jython and JRuby are
a natural fit.

Yes, I agree. Sorry, I think you missed my point -- I should probably
have said "but" or "whereas" or something in there -- Most of the
languages mentioned are just research toys, BUT (I went on to say)
Jython and Groovy (and JRuby, if you say so, I know less about that) do
have real-world uses.
Righto.
I hadn't seen Scala before ... it looks very Java-like (perhaps
unsurprisingly) and I'm not sure quite what makes it different, on a
first glance. I'll obviously have to read further.
From what I've seen it has some similarities to C# 3, but taken a bit
further. It supports a functional style of programming much more
neatly than Java does. It may also have some dynamic aspects, although
I can't remember offhand.
I haven't replied to your other posts about LINQ, by the way, but I
think you'd be wise to look into it further ...

I certainly don't know much about it ... usually it's been discussed as
a way to bind databases to C# code (and it all seemed very reminiscent
of the hype that ODBC got when it was new). I'll look further, thanks
for the "heads up".
Yup, it's unfortunate that the SQL side of things is what's gained the
most attention. I wouldn't like to try to describe it in just a few
sentences - I'm sure you'll have more joy investigating it properly :)

Jon
Jun 27 '08 #98
Daniel James wrote:
In article news:<ut******* *******@TK2MSFT NGP06.phx.gbl>, Hendrik
Schober wrote:
>Usually iostreams are implemented using the 'printf()' family,

That's obviously an easy-but-naive implementation, I'd hope that as C++
continued to mature quick hacks like that would disappear.

Certainly the current Visual C++ (Dinkumware) runtime doesn't seem to
use sprintf.
That would have been a pleasant surprise. But outputting
an 'int' using '<<' certainly lands you in 'sprintf()'. :(
Daniel.
Schobi
Jun 27 '08 #99
Daniel James wrote:
OTOH A remember being very impressed with the AppletMagic Ada for JVM
when I first looked at it -- too long ago now -- but I'm not sure it's
still around. Ada is a real language (one that really deserves to be
better known outside the war-toys factories) and it's interesting that
you can run it well on the JVM.
Also AdaCore has recently developed a version of the GNAT Ada compiler
that targets the CLR. I haven't played with it much (yet), however.

Peter
Jun 27 '08 #100

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

Similar topics

3
11268
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how to send data via POST over https and recieve data from the Authorize.net server over an https...
2
5865
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
23053
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
0
8508
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => /usr/local/lib/libstdc++.so.5 libm.so.1 => /usr/lib/libm.so.1
1
8621
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have...
4
18317
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid that? I tried registering all POST and GET vars as SESSION vars but
1
6890
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31469
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23617
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a 3x3. Any suggestions to where I should read or look would be appreciated.
0
9967
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
9810
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
11202
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
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7998
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
7151
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();...
0
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4650
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.