473,883 Members | 1,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why still use C?

no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

i heard people say C++ is slower than C but i can't believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.

in C there arent the simplest things present like constants, each struct and
enum have to be prefixed with "struct" and "enum". iam sure there is much
more.

i don't get it why people program in C and faking OOP features(functi on
pointers in structs..) instead of using C++. are they simply masochists or
is there a logical reason?

i feel C has to benefit against C++.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05
687 23872
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
Alexander Terekhov wrote:
E. Robert Tisdale wrote:
Alexander Terekhov wrote:

So, there is some "intrinsic difference in performance", I'm afraid.

No.

There is no difference in performance
unless an exception is actually thrown.

There is certainly a difference in performance between languages which
support exception handling (or equivalent feature) and those that don't.
The difference is generally small, but it does exist. Compilers have
less freedom to reorder code that might throw exceptions.

Consider, for example, the following function:

int foo() {
static int x = 0;
bar();
x = x + 1;
return x;
}

Since the address of "x" is not taken, the compiler can be sure that
it won't be used in bar(). If it is sure that bar() won't throw an
exception, then it can evaluate "x + 1" and store the result back into
"x" _in parallel_ with evaluating the function call.

However, in C, any function might call longjmp().
This feature is quite similar in power to exception handling --
it can for instance easily be used to implement exception handling
(see e.g. my C exception handling library CXCPT
<http://www.cs.mu.oz.au/~fjh/CXCPT/index.html>).
So I'm not sure if there is any intrinsic difference between
C and C++ in this regard.
http://www.computer.org/concurrency/pd2000/p4072abs.htm
("C++ Exception Handling", Christophe de Dinechin,
IEEE Concurrency October-December 2000 (Vol. 8, No. 4))
According to Bjarne Stoustrup, "The C++ Programming Language:
Third Edition", Chapter 14 Exception Handling,
Section 8 Exceptions and Efficiency, page 381:

"In principle, exception handling can be implemented so that
there is no run-time overhead when no exception is thrown."


That's true to a first approximation, but I'm not yet convinced
that it is true to a second approximation.
This principle has been realized in practice.


Are you sure? Which implementation realizes it?

The following is from a KAI C++ exception exception handling tutorial
<http://www.hlrs.de/organization/tsc/services/tools/docu/kcc/tutorials/exceptions.html >:

| General point: Some implementations of C++ claim to have "zero overhead"
| exceptions. This is impossible as exceptions inherently add new paths of
| control flow to a program. What they really mean by "zero overhead" is
| "prepaid overhead". (I like the vendor who advertises "zero overhead",
| but has a switch to turn off exceptions to enable a "faster smaller
| executable".)
|
| The way to find out what the overhead is for exception handling is
| to benchmark your own application with it turned on and off. In our
| experience, the overhead is usually in the 1-10% range.

--
Fergus Henderson <fj*@cs.mu.oz.a u> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
Nov 13 '05 #171
In article <bm**********@g lue.ucr.edu>, th*@cs.ucr.edu wrote:
In comp.std.c Alexander Terekhov <te******@web.d e> wrote:
+
+ th*@cs.ucr.edu wrote:
+ [...]
+> C is pretty much, but not quite, a sublanguage of C++. C programmers
+> who don't use the non-C++ features of C are programming in C++ whether
+> they claim to or not. They are restricting themselves to an older,
+> more established, more easily learned, and more easily implemented
+> subset of C++. But they are writing in C++ --- non-idiomatic C++, but
+> C++ nevertheless. AFAIK, a C++ compile is free to generate the same
+> code for those programs as would a C compiler, so there is no
+> intrinsic difference in performance.
+
+ In C without exceptions (stuff like MS or DEC/HP SEH extensions), all
+ functions are kinda "throw()". In the current C++ (without mandatory
+ 2-phase EH and with brain-damaged exception specifications instead),
+ throw() is kinda expensive. So, there is some "intrinsic difference
+ in performance", I'm afraid.

Huh? We're talking about code that is conforming under both C
(perhaps I should specify C89/90) and C++. Are you saying that there
are some such programs for which a C++ compiler must generate code
that is somehow different from what a C compiler would/could generate?


size_t s = sizeof ('a');

will set s to sizeof (char) = 1 on all C++ compilers, and set s to
sizeof (int) on C compilers, which is in practice greater than 1.
Nov 13 '05 #172
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote:
Alexander Terekhov wrote:
So, there is some "intrinsic difference in performance", I'm afraid.


No.

There is no difference in performance
unless an exception is actually thrown.
But C++ programs that handle exceptions
can be much "fatter" than C (or C++) programs
that don't handle exception.
This doesn't usually make much difference
on modern microprocessors with large code memories.


You are Bill Gates, and I claim my five pounds.

Richard
Nov 13 '05 #173

Fergus Henderson wrote:
[...]
However, in C, any function might call longjmp().
Oh yeah. Apart from straight deprecation, that thing just ought to
throw "std::jump_exce ption" (caught by a handler kinda "injected" by
setjmp()) or something like that.
This feature is quite similar in power to exception handling --
it can for instance easily be used to implement exception handling
(see e.g. my C exception handling library CXCPT
<http://www.cs.mu.oz.au/~fjh/CXCPT/index.html>).
So I'm not sure if there is any intrinsic difference between
C and C++ in this regard.
"All accessible objects have values, and all other components of the
abstract machine 209) have state, as of the time the longjmp function
was called, except that the values of objects of automatic storage
duration that are local to the function containing the invocation of
the corresponding setjmp macro that do not have volatile-qualified
type and have been changed between the setjmp invocation and longjmp
call are indeterminate."

http://h30097.www3.hp.com/docs/base_...rules_volatile

"1. Values of updated_volatil e and updated_before_ try are reliable.
Values of updated and updated_static are unreliable.

2. Regardless of the path to this code, the values of
updated_volatil e and updated_before_ try are reliable. If this
code is reached after the ENDTRY macro is invoked and no
exception has been raised, the values of updated and
updated_static are reliable. If this code is reached after the
exception fully_handled_e xception has been caught,
the values of updated and updated_static are unreliable.

The code in Example 5-15 demonstrates:

- For variables referenced within exception handler code blocks,
it is necessary to distinguish between those whose value is set
before versus after the TRY macro is invoked in order to declare
those variables properly.

- The requirement to use the volatile type qualifier pertains to
a variable regardless of its C storage class -- that is, for both
automatic and static variables). "

;-)

Now, don't you think that "landing pads" is kinda better approach?
http://www.computer.org/concurrency/pd2000/p4072abs.htm
("C++ Exception Handling", Christophe de Dinechin,
IEEE Concurrency October-December 2000 (Vol. 8, No. 4))


According to Bjarne Stoustrup, "The C++ Programming Language:
Third Edition", Chapter 14 Exception Handling,
Section 8 Exceptions and Efficiency, page 381:

"In principle, exception handling can be implemented so that
there is no run-time overhead when no exception is thrown."


That's true to a first approximation, but I'm not yet convinced
that it is true to a second approximation.
This principle has been realized in practice.


Are you sure? Which implementation realizes it?

The following is from a KAI C++ exception exception handling tutorial
<http://www.hlrs.de/organization/tsc/services/tools/docu/kcc/tutorials/exceptions.html >:

| General point: Some implementations of C++ claim to have "zero overhead"
| exceptions. This is impossible as exceptions inherently add new paths of
| control flow to a program. What they really mean by "zero overhead" is
| "prepaid overhead". (I like the vendor who advertises "zero overhead",
| but has a switch to turn off exceptions to enable a "faster smaller
| executable".)
|
| The way to find out what the overhead is for exception handling is
| to benchmark your own application with it turned on and off. In our
| experience, the overhead is usually in the 1-10% range.


I believe that "the right thing" is that if you have declared ALL your
functions throw()-nothing (and don't use any try-catch/throw... I
mean things like setjmp/longjmp ;-) ) than the only "overhead" shall be
one single "phase one" handler:

__try {
// ... ctors for non-local objects of static duration in C++
exit(main());
// ... dtors for local objects of static duration in C++
}
__except(goto_u nexpected()) {}

(threads and "better main" aside for a moment)

This does require two-phase EH and a bit different semantics for ES --
violations shall NOT unwind, they shall simply trigger std::unexpected ()
processing at throw points.

regards,
alexander.
Nov 13 '05 #174
On Tue, 14 Oct 2003 03:04:16 +0000 (UTC), in comp.lang.c ,
th*@cs.ucr.edu wrote:
In comp.std.c Alexander Terekhov <te******@web.d e> wrote:


Stuff which seemed to mostly be about C vs C++, and offtopic in both
CLC and CSC. This thread is dead I think ?

Also Tom can you use "normal" quotation style, your + signs doesn't
work with my newsreader.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #175

Mark McIntyre wrote:

On Tue, 14 Oct 2003 03:04:16 +0000 (UTC), in comp.lang.c ,
th*@cs.ucr.edu wrote:
In comp.std.c Alexander Terekhov <te******@web.d e> wrote:


Stuff which seemed to mostly be about C vs C++, and offtopic in both
CLC and CSC. This thread is dead I think ?


Next silly question?

regards,
alexander.
Nov 13 '05 #176
> Is it feasible to interpose a proxy library whose headers are
conforming C code that's compiled with a C++ compiler and that calls
functions from the C++ library?

when you have a C++ Library you can only call C-Style-Functions from that
Library. You cannot export Classes/Methods from that Library.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #177
Chris Hills <ch***@phaedsys .org> writes:
In article <cl************ ****@plethora.n et>, th*@cs.ucr.edu writes
In comp.std.c cody <NO************ ****@gmx.net> wrote:

C is pretty much, but not quite, a sublanguage of C++.


C++ is based on C90 However C++ is no longer a super set of C. They are
different languages.


C++ has never been a strict superset of any version of C. C++ has
several keywords that are not reserved in C; that alone makes prevents
it from being a superset.

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #178
On 12 Oct 2003 22:49:25 GMT
Chris Hills <ch***@phaedsys .org> wrote:
C++ is based on C90 However C++ is no longer a super set of C. They
are different languages. <snip> This is not true. The are using C. C++ Inherits from C NOT the other
way round.

I think that members of both the standards committee tried to keep the
standards as coordinated as possible. C++ dropped a lot of the C legacy
(K&R) stuff.
But also C99 added the // comment which is illegal in C90.
--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053 C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #179
In article <cl************ ****@plethora.n et>, Chris Hills
<ch***@phaedsys .org> writes
A wild guess is that every minute of the day, there is more micro
processor code running than PC code running. (?)


According to figures I have seen from several silicon vendors (they vary
slightly but they average out at about 1 in 3 processors on (and above)
the planet is an 8051....

PC x86 processors make up less than 10% of the total the other 88% are
embedded systems... (the 2% are MACs and mainframes.)

I am sure the figures have changed in detail but it gives a fair
picture.


No one who understands the degree to which embedded systems pervade our
technological societies would argue that the processors in general
purpose computers represent anything but a a very small part of the
population of processors in use. However the step from that to the
volume of code running at any given time is far more debatable. 8051
based equipment tends to be running very small amounts of code
relatively slowly, quite apart from anything else high clock speeds are
very power hungry so running an 8051 at 2GHz would be inappropriate.

General purpose computer tend to run very large volumes of, often flaky,
code very fast. Of course there is embedded code running on very fast
processors (e.g. the latest high end graphics cards that are so power
hungry that they need to take power directly from the power unit and not
from the motherboard.) OTOH embedded processor code tends to be compact
and carefully honed code which is relatively error free. I would hazard
a guess that the hours of development time per code instruction is an
order of magnitude (or possibly 2 or even 3 orders) higher than that for
even for operating systems for PCs.

There is also the issue as to whether the code running on the graphics
card, sound card etc. counts as PC code or embedded processor code.

--
Francis Glassborow ACCU
If you are not using up-to-date virus protection you should not be reading
this. Viruses do not just hurt the infected but the whole community.
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #180

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

Similar topics

3
11266
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
31461
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
9791
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
11137
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
10742
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...
0
10410
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
7970
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
7122
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
5797
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...
1
4609
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
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.