473,883 Members | 1,600 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 23893
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++. :-)

--
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 #281
Kevin D. Quitt <KQ**********@I EEInc.MUNG.com> writes:
On Sat, 18 Oct 2003 09:27:07 +0000 (UTC), 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.


The one does not follow from the other.


What doesn't follow from what? I think Kevin is defining the term
"semantic intersection".
It's my
impession that the intersecton includes the majority of actual C
programs.


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


I'm reasonably sure that the majority of actual C programs do not
contain that macro definition.

I'm also reasonably sure that the majority of actual C programs do not
apply the sizeof operator to a character constant.

I haven't tried compiling a large body of C programs with a C++
compiler, but I'd guess that one of the most common sources of
incompatibility is calls to malloc() with no cast (legal and strongly
recommended in C, illegal in C++). Use of C++ keywords as identifiers
is probably less common, though it's certainly an issue.

--
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"
Nov 13 '05 #282
On Sat, 18 Oct 2003 13:18:17 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
Christian Bau wrote:
[snip]
However, the majority of actual C programs can be changed with little
effort into source code that has identical behavior as C and C++
programs. The most annoying difference is having to cast the result of
malloc in C++, which is considered bad practice in C and necessary in
C++.


Why is it considered "bad practice"? I know it is frowned upon
sometimes, but I fail to see the rationale for that.


The function of a cast is to silence a compiler warning. Thats not a
good idea, generally. Its easy to get carried away with them.
One advantage of casting malloc() results is that, like you say, one has
a fighting chance of getting a clean (error/warning-less) compile using
C++ in addition to getting a clean compile in C.
Clean in the sense of "doesn't warn about errors", yes. And this is
good because?
For me, compiling a piece of code with as many compilers as I can get my
hands on (with maximum warning levels) has proven to be a great way of
catching problems; different compilers give different warnings.
Indeed.
Having one's C program compilable by a C++-compiler also helps, since
this can sometimes flag potential problems in the C code that are not
noticed by a C compiler.


Thats a QOI issue. Get a better C compiler.
--
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 #283
On Sat, 18 Oct 2003 17:23:02 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
and I am not going to drop casts that are not needed
just because the standard allows me to. I feel my code looks
prettier with malloc() casts.
what, you think this looks prettier
foo = (struct myweirdstruct*) malloc( sizeof (myweirdstruct) );
than
foo = malloc (sizeof *foo);
???????
2. Casting malloc's return value may hide the (admittedly simple to fix)
error of not providing a proper prototype for malloc.


If this is the case, I seriously doubt the quality of the compiler:


Many compilers only *warn* about implicit function declarations on
their default warning level. My "many" I mean "pretty much all the
popular ones"
The standard doesn't require the compiler to issue a warning of course
(never does), but I think, the year being AD2003 and all, that a
good-quality compiler should issue a warning whether the (char *) cast
is there or not.
A warning is typically not a compilation halting operation. Thus
during an automated build, this error might go unnoticed.
Having one's C program compilable by a C++-compiler also helps, since
this can sometimes flag potential problems in the C code that are not
noticed by a C compiler.


<snip enum example claiming ti support this>
This is a perfectly legal C program as far as I can tell, and it's
illegal in C++ due to the attempt to implicitly casting 1 to EType.
but in C, this is not an error.
I think C++ is right to flag this as erroneous, and require a cast.


not in C, its not. Remember that enums are not a new type in C,
they're ints. So you are inserting another useless cast, obfuscating
your code slightly for no benefit.
--
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 #284
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... :-)
--
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 #285
Sidney Cadot <si****@jigsaw. nl> wrote:
Irrwahn Grausewitz wrote: <snip>
If you think that C99 6.3.2.3 is a mistake, you should submit a DR or a
proposal to the standards comittee. ;-)


Perhaps I should do that! And hopefully I could convince them to retract
support for those butt-ugly // comments as well :-)


It's strange: I always wanted to have these single line comments in C,
now I can use them and already learnt to hate 'em :)

<snip>My point is that a decent modern compiler will warn on the implicit
declaration of malloc() anyway, with an appropriate warning level. <snip>Again, I'm not advocating leaving out #include <stdlib.h> ; we're just
comparing compile-time behavior for different malloc() handling. <snip>No, that's not what I said. My opinion is this: A decent C89 compiler
should be able to warn on non-prototyped functions being used, even
though C89 allows it. <snip>... You misunderstood my definition. All compilers I've used are able to
warn on non-prototyped function usage.
I was off-track then.

<snip>
Caricatures have the advantage of exposing certain aspects by hyperbole.
In one sense they are /defined/ that way. :o)


Chapter and verse? :-)


C99 6.2.8#2 :-))
Here's another one:
A perfectely valid Spanish sentence can also be a perfectly valid
Portugese sentence, but with a different meaning. The fact that both
are somewhat close related languages doens't make them compatible.


...Now suppose you have a machine that understands Spanish, and a
machine that understands Portugese. Both machines warn on incorrect
syntax and grammer in their respectively understood languages. Let's
also assume (to make the metaphor a bit more realistic) that Portugese
descends from Spanish, adding a few grammatic constructs, and that most
Spanish sentences (except from contrived examples) are also correct
Portugese (though not the other way round). Finally, let's assume
Portugese is a lot stricter concerning grammatical constructs; some
sentences that are legal Spanish but often lead to problems are
incorrect in Portugese.

Now we have a valid metaphor. I'm advocating that, if you try to write
problem-free Spanish, using both machines instead of just the Spanish
one can be of help.


But doing so you would have to avoid some common spanish idioms, which
will likely result in constructs that sound strange to native Spanish
speaking persons - the human readers of your code, to stress the
metaphor even more.

<snip>I would kindly refer you to my reply to Cody's questions of 5 october. I
prefer C for many reasons, but I also recognise that C++ aims to fix
some problems in C. I'm aiming for the 'best of both worlds' approach.
But why not use tools that are specially designed for testing C code?
What if the common subset of C and C++ becomes smaller after some more
revisions of the standards? The 'best of both worlds' may turn into the
'worst of both worlds' some day...

<example code snipped>
I think C++ is right to flag this as erroneous, and require a cast.


Hm, "right" depends of ones POV in this case. The C standard does not
require a diagnostic, so it is wrong? I don't think so.


It's not wrong from the C standard's point-of-view, but then I feel the
C standard is wrong in this respect. The rationale for allowing implicit
int-to-enum conversion at the time was undoubtedly the desire to not
break existing code, but as far as I am concerned the time has come to
leave this behind for new code.


I agree that the "oh no, don't break existing code" concept breeds the
danger of stagnation. And the "lack" of typesafety in C is, has been
and will probably always be a debatable point. I feel comfortable with
it as it is, otherwise I'd probably use some other language. Though
one has to watch ones step very carefully.

<snip>
Then please tell me where the common subset of C and C++ is
defined, so I have something to make my code comply to, just in case I
want to code the same way you do; is it different for C89 compared to
C99? Please give a reference.


What's so strange about the concept of the intersection of two related
languages for which standards exists? Now I'm quite willing to explain
what an intersection is and to provide pointers to the relevant
standards, but you will first have to explain to me what's so hard to
understand :-)


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? :-)

<snip>I think you were (I'm trying hard to avoid it), but I am happy to see
that we can resolve this without erecting, much less burning, any straw
men.


Speaking of burning, I have to turn the heating on...
Regards, and have a nice weekend.


You too. I mean, what could be more fun than arguing coding style on
Saturday evening!


Definitely! ;-)

Regards
--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #286
On Sat, 18 Oct 2003 23:04:51 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
foop barp;
barp = (foop)malloc(co unt * sizeof *barp);


its not supposed to /prevent/ you from writing it, its supposed to
prevent you from /needing/ to write it.

By using CBF's method, you can change the type of barp, and ripple
that through all your code, by changing only one line of code, instead
of the 1000s of places you've malloced barps. Sure, you still have to
chagne places that you *use* a barp, but you've still reduced
maintenance costs sharply.

What do you thin that casting malloc does? How does it improve either
your code quality or readability? Its a serious question.
--
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 #287
On Sat, 18 Oct 2003 21:06:37 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
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++. :-)


Consider the value of "true" in juxtaposition with the previous
poster's statement.

--
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 #288
"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.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 13 '05 #289
Mark McIntyre wrote:
[[casting malloc result]]
Why is it considered "bad practice"? I know it is frowned upon
sometimes, but I fail to see the rationale for that.

The function of a cast is to silence a compiler warning. Thats not a
good idea, generally. Its easy to get carried away with them.


That's a very negative way of putting it. 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.

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.
One advantage of casting malloc() results is that, like you say, one has
a fighting chance of getting a clean (error/warning-less) compile using
C++ in addition to getting a clean compile in C.


Clean in the sense of "doesn't warn about errors", yes. And this is
good because?


I don't quite know what 'doesn't warn about errors' could mean, but
anyway. This is good because I can get my program compiled by the C++
compiler and get to an executable that I can run. 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.
Having one's C program compilable by a C++-compiler also helps, since
this can sometimes flag potential problems in the C code that are not
noticed by a C compiler.


Thats a QOI issue. Get a better C compiler.


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? Problems don't disappear by qualifying
them as QOI.

Best regards,

Sidney Cadot

Nov 13 '05 #290

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
9936
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...
1
10845
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
9571
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
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
7123
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...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.