473,889 Members | 1,406 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 23917
On Mon, 20 Oct 2003 01:13:38 +0200, Sidney Cadot wrote:
But surely, I am. It can now detect assignment to the wrong type of
pointer, for example:

int *x = malloc(1000*siz eof(double)) /* would go unnoticed */
int *y = (double*)malloc (1000*sizeof(do uble)) /* would be noticed */


And to combat your idot proofing the world makes a better idiot...

int *x = (int *)malloc(10 * sizeof(short));
int *y = (int *)malloc(10);
int *z = (int *)malloc(0 * sizeof(int));

....I could _maybe_ understand the desire for something like g_new(), where
you do...

#define foo_new(T, n) ((T *)calloc((n), sizeof(T)))

int *x = foo_new(int, 10);

....but I fail to see how going from typing something once to typing it
twice improves anything.

--
James Antill -- ja***@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/

Nov 13 '05 #331
thp
In comp.std.c Jonathan Leffler <jl******@earth link.net> wrote:
+ 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, the code I work on has one structure with a member class. It
+ also has a depressing lack of prototypes in the function definitions,
+ even though all the functions (well, most of them) have prototype
+ declarations (as well as non-prototype declarations - despite the fact
+ that we don't have any non-ANSI compilers to support). I've tried to
+ get some of this stuff fixed up, but the corpus is too large and there
+ are too many uninterested parties in charge of it to actually clean it
+ up. I fantasize about getting it clean enough to compile under a C++
+ compiler - not because we'd necessarily want to release such a
+ version, but simply because so much of the code would have been
+ improved in order to get to the point where that was possible.
+ Depressingly, it has been hard work to get people to the point where
+ 'gcc -Wall -Wmissing-prototypes -Wstrict-prototypes' compiles
+ reasonably cleanly - we are not there yet. The volume of code?
+ Multiple millions of lines in total.

In principle, it shouldn't be that difficult to for a syntax-savvy
preprocessor to cast problematic void* assignments, e.g., return
values from malloc. Similarly it shouldn't be difficult to deal with
C-program identifiers that collide with C++ keywords by decorating
them with some suitable prefix or suffix.

In principle a short script could do such things.

In principle, principle and practice are one; in practice, they're
not.

Tom Payne
Nov 13 '05 #332
Sidney Cadot <si****@jigsaw. nl> wrote in message news:<bm******* ***@news.tudelf t.nl>...
James Kuyper wrote:

....
In C, you're not helping the compiler in any way.


But surely, I am. It can now detect assignment to the wrong type of
pointer, for example:

int *x = malloc(1000*siz eof(double)) /* would go unnoticed */
int *y = (double*)malloc (1000*sizeof(do uble)) /* would be noticed */


Is C/C++ your normal programming language? Even moderately experienced
C/C++ programmers quickly become compulsive about putting in ';' where
needed. Just wondering, that's not intended as an attack.

Back to the actual issues, here's another case:

int *y = (int*)malloc(10 00*sizeof(doubl e)); // would be unnoticed

The type checking that you get from

T *p = (T*)malloc(expr ession);

is not very useful, because it's extremely rare to change one of the
'T's without changing the other one, and when it does happen the
correction is usually that you need to change the second one to match
the first. That correction produces exactly the same effect that you
would get automatically if you removed the cast.

On the other hand, the cast disables the validity check that you would
otherwise get if the declaration of malloc() is either missing or
specifies an incompatible return type, and that's a much more
important validity check.
Inserting the cast
wouldn't make it become a double* any earlier than it would without
the cast.


Yes it would. See above.


I've seen above, and I don't see anything relevant. There's not a
single event that happens between the time that it would be converted
to void with the cast, and the time it would be converted to double*
without the cast. Therefore, in what sense is it "earlier"?
> 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.


This whole discussion is based on my assertion that it is sometimes
useful to be able to compile a C program with a C++ compiler.


You misunderstand me. You want to compile a C program using a C++
compiler, solely for the purpose of the dubious benefit of better
error handling. If that does in fact produce better error handling,
that indicates that you have a low quality C compiler. Your proper
response should be to get another one.

I was talking about someone who actually needs to compile with C++
because they need their code to work in a C++ context, not just for
the error checking. In that situation, your approach would make a lot
more sense.

....
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.


I'm trying to argue that C++ is rightly more picky about some things
that are (unfortunately) legal C. See my enum example in a previous post.


C++ is rightly more picky about things that C++ needs to be more picky
about; if a C program actually needs to be more picky about them too,
then a decent C compiler will warn about them, despite the fact that
they're legal C.
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.


I think implicit int->enum conversions are a problem, notwithstanding it
is allowed in C.


Then a good C compiler should have the option of warning you about
them.
Nov 13 '05 #333
"P.J. Plauger" <pj*@dinkumware .com> wrote in message news:<O8******* ***********@nwr ddc01.gnilink.n et>...
"James Kuyper" <ku****@wizard. net> wrote in message
news:8b******** *************** ***@posting.goo gle.com... ....
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. :-(


I married a nice Catholic girl. I told the priest who registered our banns
that I was raised in a Protestant household. That didn't bother him too
much until I observed that I never quite got around to being baptized.
At that point, he wrote 'heathen' next to my name and literally sent me
out of the room. Never spoke to me again, in fact.

.... For the record -- and your C question is?


Sorry, there's none - but this is an unmoderated newsgroup, so it's
possible to wander off topic a little. I posted to the group, rather
than asking by e-mail, because I wanted to push a little for the
legitimacy publically admitted heathenism. However, if you call
yourself a Protestant, you're nowhere near as much of a heathen as I
am, no matter what the priest said. Therefore, posting this to the
group didn't really serve my intended purpose.
Nov 13 '05 #334
"James Kuyper" <ku****@wizard. net> wrote in message
news:8b******** *************** ***@posting.goo gle.com...
"P.J. Plauger" <pj*@dinkumware .com> wrote in message news:<O8******* ***********@nwr ddc01.gnilink.n et>...
"James Kuyper" <ku****@wizard. net> wrote in message
news:8b******** *************** ***@posting.goo gle.com...

...
> 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. :-(


I married a nice Catholic girl. I told the priest who registered our banns
that I was raised in a Protestant household. That didn't bother him too
much until I observed that I never quite got around to being baptized.
At that point, he wrote 'heathen' next to my name and literally sent me
out of the room. Never spoke to me again, in fact.

...
For the record -- and your C question is?


Sorry, there's none - but this is an unmoderated newsgroup, so it's
possible to wander off topic a little.


Don't be sorry. I meant it as a joke. And I'm constitutionall y incapable
of writing emoticons to underscore the intent.
I posted to the group, rather
than asking by e-mail, because I wanted to push a little for the
legitimacy publically admitted heathenism. However, if you call
yourself a Protestant, you're nowhere near as much of a heathen as I
am, no matter what the priest said. Therefore, posting this to the
group didn't really serve my intended purpose.


I didn't say I was a Protestant, merely that I was raised in a Protestant
household. In fact, I deliberately keep private my personal religious
views, for a host of reasons. That's something between me, myself, and --
whatever. You will note, however, that I do celebrate my *official*
heathenhood. So maybe your posting served your purpose better than you
think.

And your Visual Basic question is?

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 13 '05 #335
In article <bm**********@n ews.tudelft.nl> ,
Sidney Cadot <si****@jigsaw. nl> wrote:
Mark McIntyre wrote:
[...] 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);
???????


Well yes, although I feel

foo = (struct myweirdstruct *)malloc(sizeof (struct myweirdstruct)) ;

looks prettier still.


How 'bout this one?
foo=(int (*)[17][42])malloc(105 * sizeof(int (*)[17][42]));
(Compare to:
foo=malloc(105* sizeof *foo);
I like this one much better.)
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca
Have some pride, you're a physics major! You know deep in your heart
you're better than the rest of the slobs there, you should be able to
knock this course off easily. --Brian B. Rodenborn in comp.lang.c
Nov 13 '05 #336
"P.J. Plauger" wrote:
FWIW, I used your style for over 20 years, including a decade
after I added void * to my compiler. Then one day, about ten years
ago, I sat down and added casts to every blessed malloc call in my
living code base. And I've never been sorry. A more curious person
might wonder why.


Some of us are just too tickled pink to hear someone with your
"weight" weigh in in favor of casting malloc() to wonder why....

(-:

--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
Nov 13 '05 #337
On Mon, 20 Oct 2003 01:30:19 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
Mark McIntyre wrote:
On Sun, 19 Oct 2003 15:53:52 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:

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,


but the compiler does, because you assign the return of malloc to a
double*.


Please read carefully. I was talking about the malloc expression, not
the assignment expression.


Please *think* carefully. malloc() itself has *no need* to know the
type of what you're going to point the memory to later. The soonest
anything needs to know is when the result of malloc is assigned to a
pointer. At which point the magic of C converts it to a correctly
aligned block of memory for the relevant type of object.
I will help the compiler a bit to change the
returned value to (double *) ASAP.

The compiler doesn't need this help. It automatically does it just as
soon as possible, merely because you assigned it to a double. It can't
happen any faster than that.


... So how to you explain the error on:

int *x = (double *)malloc(1000*s izeof(double))


The only error here is in using a poor style.
int *x = malloc (1000 * sizeof *x); // look ma, no possible errors

Plus, just in case it slipped your attention during your increasingly
frenzied defence, the insertion of the cast doesn't help the compiler
either.
Then your experience is more limited than you think.


If it makes you happy to think so, be my guest.


It makes me /un/happy to think that someone who's exhibiting such
limited experience and muddle headed thinking can fail to see their
glaring mistakes.
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.


No, it can't. It can only *introduce* them, or fool you into thinking
you've found an error that is NOT an error.


I chose the word "mistakes" on purpose, and you're talking about an
"error". These two are different things (e.g., passing an integer to an
enum parameter is not an error in C, but in my coding style it's a mistake).


*shrug*. I can't help it if you insist in using C++ idioms but writing
C. Why not just write C++ ?
>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
representab le 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++.
That does not answer my question.


Yes it does. You're being obtuse, or stupid, or silly, either is
applicable.
"Being a practical person", please provide an example of C code in
which the fact that you pass an int where an int is expected, matters.


If you like using ints and enums interchangeably , that's fine by me.
Just don't expect the same of me please.


And now answer the 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 #338
On Mon, 20 Oct 2003 01:55:43 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
Mark McIntyre wrote:
but *what* potential problems? if you C compiler isn't flagging them,
then either
a) its a bad C compiler: get another, or
b) its not actually an error in the first place, and you have a
serious misunderstandin g of C.
Again, you've changed "potential problem" into "error". The distinction
is important.


okay, I'll bite. *What* potential "problems" will your C++ compiler
catch?
Tell me, do you refuse to use the warning
facilities by your favorite C compiler? If not, why not?

How does this relate to your insistence in compiling your C as C++ "to
trap potential errors?"


You don't seem to make the distinction between potential problems and
errors, flagged as such by the compiler.


What distinction? Either its an error, or its ok. Which is it?
I want to make this distincion
clear in order to explain the rationale for compiling my C code using a
C++ compiler; you are quite stubbornly refusing to admit that this way
of working could expose problems.
ROFL. I'm quite stubbornly refusing to let you get away with blanket
unfounded and unprovable statements you mean.
I am happy to write
if ((x=foo()) bar();
which shuts up the error, in gcc at least.

By doing this I am making a concession to the compiler. Likewise, I make
the concession of casting malloc results, in order to be able to trace
down more problems (not 'errors') with a C++ compile of my C code.
There's a world of difference between writing C++ style C code in
order to silence your C++ compiler which you gratuitously used because
you *think* it will help spot bugs in your C, and writing gnu style C
code, to silence your gnu compiler from complaining about real
possible errors.
Now I am quite sure that you would use warnings, and I am guessing that
you would also make these kinds of (small) concessions to the C compiler
to get more warnings.
If that is the case, why the knee-jerk reaction to my casting of malloc
results? I think they're quite equivalent things.


*shrug*.
I don't. I think you're trying to talk yourself out of a corner, and
failing.

--
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 #339
CBFalconer wrote:
I and, apparently, almost everyone else, thinks that
your malloc casts are ridiculous.
I don't think that they are ridiculous.
The only possible reason for them is to compile with C++
which all consider a spurious reason.
I don't think that it is a spurious reason.
C++ is, after all, the future of C.
However, the enum <-> int case is different.
It is the only way, apart from struct,
to truly create a new data type in C.
Evidently, Brian W. Kernighan and Dennis M. Ritchie
disagree with you,
"The C Programming Language: Second Edition",
Appendix A: Reference Manual,
Section 4: Meaning of Identifiers,
Subsection 3: Derived Types, page 196.
As long as those assignments go unflagged,
it does very little good (but is not useless).
I think you (and I) would be happy
if gcc could be told to emit a warning for such usages.


Nov 13 '05 #340

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
9805
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
11188
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
10439
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...
0
7148
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
5825
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
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3253
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.