473,889 Members | 1,350 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 23922
Mark McIntyre wrote:
As far as I am concerned, a
pointer cast is a way of expressing the fact that the compiler-inferred
type of the object pointed to by a pointer differs from the type that I,
the programmer, know to be the real type pointed at.

Sure. When you're using implementation defined behaviour, the compiler
can't correctly convert automatically, so it needs a hint. Thats fine.
Sometimes the compiler cannot infer the type properly and needs a bit of
help. I would argue that the malloc() is just such a case.


??? with malloc() the compiler can always infer the correct type.


If I have the expression...

malloc(1000*siz eof(double))

....with the intent of using its value as a 1000-element array of doubles
later on, it should have type (double *), not type (void *). Since
malloc() doesn't know this, I will help the compiler a bit to change the
returned value to (double *) ASAP.

Just because you would usually write something like

double *x = malloc(1000*siz eof(double))

.... which makes the problem go away soon enough, doesn't mean that the
type of the malloc expression alone should be allowed to be (void *)
longer than necessary.
Ah, good in the sense of "make it compile on a non-C compiler". This
is obviously some strange new definition of good I was not previously
aware of !
Apparently.
This is an interesting
exercise, because any behaviorial mismatch between the program as
produced by the C compiler and by the C++ compiler could point to
something I have overlooked in the C code. Possible but unlikely - its more likely that the C++ compiler will
pick up on C++ errors which are correct C, and fool you into
"correcting " them badly.
Not in my experience.
BTW do you also try to compile with a fortran and pascal compiler? To be sure?


Is it really needed to aim for ridicule?

But to answer your question: No, since this doesn't help to reduce
mistakes in my C code I don't. C++ however can help in that respect.
What C compiler would you recommend, if I want a warning on an integer
being passed for an enum parameter (as in my example)? Or would you say
that I am wrong in wanting this?


since "The expression that defines the value of an enumeration
constant shall be an integer constant expression that has a value
representable as an int." [6.7.2.2(2)] I don't see that it makes no
sense to expect any C compiler to complain about this. C is not C++.


True, but being a practical person I will use any tool at my disposal to
discover and correct potential problems in my code.

Just out of curiousity: do you consider it good style to pass an integer
literal as an argument to a function expecting an enum?

If no: suspect I have a codebase where I'm replacing an integer argument
to a function with an enum, because it more accurately reflects the
purpose of that parameter. Now wouldn't it be great if the compiler
assisted me in tracing down the remnants of the old-style function
invocation?
Problems don't disappear by qualifying them as QOI.

But its still not a C problem is it?


It's not really a C problem, no -- much rather a problem with C.

Best regards,

Sidney

Nov 13 '05 #311
Christian Bau wrote:

In article <bm**********@g lue.ucr.edu>, th*@cs.ucr.edu wrote:
C and C++ have a relatively large semantic intersection, i.e., set of
programs to which C and C++ attach identical behavior. It's my
impession that the intersecton includes the majority of actual C
programs.


I think the majority of actual C programs will not compile as C++
programs at all; if the programmer never heard of C++ then it is just
too easy to have "new", "class" or "template" as an identifier.


I doubt that this problem, while quite real, affects "a majority" of
actual C programs. I think the number of C programs that wouldn't
compile because they still use unprototyped function declarations
(mainly in legacy code, one hopes) is a much larger. Does anyone care to
provide actual numbers? I have no idea where to find them.
Nov 13 '05 #312
Sidney Cadot <si****@jigsaw. nl> wrote in message news:<bm******* ***@news.tudelf t.nl>...
....
Could anybody point me to the last C89 draft standard that is publicly
available on the web? I have "n869.pdf" sitting on my HD for C99 which
is pretty useful and I would also like a similar document for C89.

If only to prevent silly mistakes like this.


A lot of changes were made between n869 and the final standard. You'd
be much better off using the actual C99 standard; it only costs $18.

I'm fairly sure that C89 is not available legally on the web; but I
could be mistaken. One reason I don't have a copy of the C89 standard
is that a legal copy was never cheap enough to be worthwhile until
just recently; and at this point I'm no longer interested.
Nov 13 '05 #313
"P.J. Plauger" <pj*@dinkumware .com> wrote in message news:<Ih******* **********@nwrd dc01.gnilink.ne t>...
"Mark McIntyre" <ma**********@s pamcop.net> wrote in message
news:nl******** *************** *********@4ax.c om...
On Sat, 18 Oct 2003 20:13:58 GMT, in comp.lang.c , "P.J. Plauger"
<pj*@dinkumware .com> wrote:

Gee, I just counted a couple of hundred casts in our C code,


PJ we already know you're a heathen, so no need to chime in... :-)


Nice of you to notice. In fact, I've been officially recognized as
a heathen by the All Catholic Church. It's a point of pride with me.


Congratulations ! How did you win this honor? No one's ever bothered
giving me official recognition. :-(
Nov 13 '05 #314
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in message news:<bm******* ***@titan.btint ernet.com>...
Mark McIntyre wrote:
The function of a cast is to silence a compiler warning.


Not so. The function of a cast is to convert "the value of the expression to
the named type." (Of course, it's the programmer's job to ensure that the
conversion is meaningful.)


I think he was referring specifically to the case of casts that are
inserted despite the fact that they don't change the actual meaning of
the code. That is, casts which mandate precisely the same conversion
that would have happened automatically even if the cast weren't there.
Nov 13 '05 #315
Sidney Cadot wrote:
....
Could anybody point me to the last C89 draft standard that is publicly
available on the web?


http://www.tkn.tu-berlin.de/~jklaue/ansic

Jirka

Nov 13 '05 #316
Sidney Cadot <si****@jigsaw. nl> wrote in message news:<bm******* ***@news.tudelf t.nl>...
Mark McIntyre wrote: .... ...with the intent of using its value as a 1000-element array of doubles
later on, it should have type (double *), not type (void *). Since
malloc() doesn't know this, I will help the compiler a bit to change the
returned value to (double *) ASAP.

Just because you would usually write something like

double *x = malloc(1000*siz eof(double))

... which makes the problem go away soon enough, doesn't mean that the
type of the malloc expression alone should be allowed to be (void *)
longer than necessary.


In C, you're not helping the compiler in any way. Inserting the cast
wouldn't make it become a double* any earlier than it would without
the cast. Either way, it still gets converted to 'double*' after the
call to malloc() and before the assignment to 'x', and there's
absolutely nothing else happening between those two events. Unless
your code actually needs to work with C++, this is pointless.

The only thing you're doing, is turning off the error or warning
messages that would occur is you had a missing declaration of 'malloc'
(C only), or a declaration of malloc() in scope with a return type
that can be converted to the destination type, but shouldn't be. In C,
this would have to be a function or function pointer with internal
linkage. It can be done with namespaces or function overloading in
C++.

There's a number of reasons why 'new' is the superior approach to this
problem in C++.
BTW do you also try to compile with a fortran and pascal compiler? To be sure?


Is it really needed to aim for ridicule?

But to answer your question: No, since this doesn't help to reduce
mistakes in my C code I don't. C++ however can help in that respect.


Not if you've got a decent C compiler. Most C++ compilers have a mode
where they compile according to C rules. Truly legitimate warnings
that are not specific to C++ should be the same in both modes.

The warnings that a C++ compiler will give you that a good C compiler
won't give you are mainly warnings about things that aren't really a
problem in C. And that's equally true if you replace "C++" with
"Fortran" or "Pascal".
Nov 13 '05 #317
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in message news:<bm******* ***@hercules.bt internet.com>.. .
Kevin D. Quitt wrote:
On Sat, 18 Oct 2003 09:27:07 +0000 (UTC), th*@cs.ucr.edu wrote:
It's my
impession that the intersecton includes the majority of actual C
programs.


#define true (1/(sizeof 'a' - 1))


Um, this resolves to 1/0 in C++, and either 1/0 or 0 in C. None of these
values is typically associated with the concept of truth in either C or
C++. :-)


In C it resolves identically with (1/(sizeof(int)-1)). That could be
0, or 1, or 1/0, depending upon sizeof(int); For that reason, it
doesn't belong in code intended to be portable. However, it is a
correct (if not particularly well-motivated) definition for 'true'
when sizeof(int)==2.
Nov 13 '05 #318
Irrwahn Grausewitz <ir*******@free net.de> wrote in message news:<41******* *************** **********@4ax. com>...
....
Hm, seems to me you didn't get my point:
It's not the concept that's hard to understand, it's just that the
mentioned intersection isn't standardized. I don't like the idea
of having to change my coding style whenever each of the standards
changes. In fact, as long as I can't claim to have "incorporat ed" at
least 80% of _one_ standard, I won't bother to even try to define the
common subset of two (or three) standards. Maybe I'm just dumb. %O
Well, we could form a committee to exactely define the common subset
of both languages, but, er, well, what shall I say? :-)


The common subset IS standardardized . It is defined by the combination
of the C99 and C++ standards. You can determine precisely which
programs are in the common subset just by reading those two standards.
Admittedly, it takes a lot of work to figure out what that common
subset is; but the work involved is analysis, not standardization .

As a starting point:
1. Don't use any features that are unique to either language.
2. Don't define identifiers that are reserved by either language in
the context where you define them.
3. Pay careful attention particularly to Annex C of the C++ standard,
which lists the main compatibility issues between the two languages.
Nov 13 '05 #319
James Kuyper wrote:
Christian Bau wrote:

In article <bm**********@g lue.ucr.edu>, th*@cs.ucr.edu wrote:
> C and C++ have a relatively large semantic intersection, i.e., set of
> programs to which C and C++ attach identical behavior. It's my
> impession that the intersecton includes the majority of actual C
> programs.


I think the majority of actual C programs will not compile as C++
programs at all; if the programmer never heard of C++ then it is just
too easy to have "new", "class" or "template" as an identifier.


I doubt that this problem, while quite real, affects "a majority" of
actual C programs. I think the number of C programs that wouldn't
compile because they still use unprototyped function declarations
(mainly in legacy code, one hopes) is a much larger. Does anyone care to
provide actual numbers? I have no idea where to find them.


Well, one place I can look is in my current development directory. I chose
the first fifty C modules I could find[1].
Below, "Yes" means "C source compiled cleanly under a C++ compiler in
conforming mode", and "No" mea... well! :-)

Yes : 13
No : 37

I was pleasantly surprised that so many "passed" the test, but not at all
surprised that so many "failed". Some of the failures were for rather
esoteric reasons, e.g. to do with constness, but most were to do with void
*, and there was the occasional keyword issue as well.
[1] Hey, I don't have all day, okay? :-)

--
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 #320

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

Similar topics

3
11267
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
9961
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
9807
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
10441
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
7993
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
7150
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
5828
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
6028
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
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
3255
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.