473,883 Members | 1,596 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
On 12 Oct 2003 22:55:32 GMT in comp.std.c, se***@plethora. net
(Seebs) wrote:
In article <cl************ ****@plethora.n et>, <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.
I thought about this a bit, and I have concluded that I disagree.

....In reality, to say you are "programmin g in C++" means not just that your
code happens to be syntactically C++, but that you have adopted the philosophy
and design of that language. Often, people whose code passes through a C++
compiler are really writing FORTRAN IV; I've seen such code.


How upsetting for you! ;^> Often, people whose code passes
through a C compiler are really writing Pascal; I've seen such
code and textbooks! How upsetting for me!

Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
--
Br**********@CS i.com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #301
On 12 Oct 2003 22:49:01 GMT, ku****@wizard.n et (James Kuyper) wrote:

"cody" <do************ *********@gmx.d e> wrote in message news:<cl******* *********@pleth ora.net>...
...
is "const float PI=3.14" possible in plain C?


Of course. Its a very bad idea, since in most cases you need a lot
more digits, but it is possible.


My favorite is

const volatile unsigned int foo = 42;
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #302
On 2003-10-18, Sidney Cadot <si****@jigsaw. nl> wrote:

Good plan. A good starting point would be the C++ standard without the
exceptions, templates, and STL parts.


http://www.caravan.net/ec2plus/

-- James
Nov 13 '05 #303

On Sun, 19 Oct 2003, Irrwahn Grausewitz wrote:

Fergus Henderson <fj*@cs.mu.oz.a u> wrote:
Jerry Feldman <ga********@blu .org> writes:
Keith Thompson <ks*@cts.com> wrote:

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.
Congratulations , you just "proved" that C99 isn't a superset[1] of C89.
Do you dispute it?
[1] According to your definition of "superset".


Do you dispute it?

Really, the definition of "superset" is a quite well-accepted
logical notion. You can't really debate it. The set of valid
C89 programs is *not* a subset of the set of valid C99 programs,
nor vice versa -- the two sets merely intersect.

-Arthur
Nov 13 '05 #304
On Sat, 18 Oct 2003 19:56:35 +0000, P.J. Plauger wrote:
Which of the following is most likely to
do the right thing, given that the type of 'p' might be hard to
remember?

extern Gronk *p;

p = (Gronk *) malloc(sizeof (Gronk));
p = (Gronk *) malloc(sizeof *p);
p = malloc(sizeof (Gronk));
p = malloc(sizeof *p);
(Hint: the last one.)
None of the above. I strongly prefer:

p = (Gronk *) malloc(N * sizeof (Gronk));

even when N is an explicit 1. (Though I do eliminate the sizeof
when the type is demonstrably a char type.)


Why don't you use calloc() ... do you like checking for integer
overflows, by hand?
And if I was going to cast all the time (I'm strongly in favour of
allowing C to do it), I would write a macro. Like...

#define new1(T) ((T *)malloc(1 * sizeof(T)))
/* much check overflow before calling */
#define newn(n, T) ((T *)malloc((n) * sizeof(T)))
Feel free. 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.


I've tried it (wanted to get some inline functions to compile under both
languages), but it's just looked too ugly to live IMO. malloc() I might be
able to live with, but it also meant I had to change code like...

Foo *foo(Bar *bar)
{
if (!bar->foo)
return (NULL);
...
}

....because C++ doesn't compile with the normal C definition of NULL. Which
affected much more code, IIRC. Then the fact that if you had anything you
passed through a (void *) then C++ made you sprinkle casts over
everything.

And really, if I only wanted the code for C++ I wouldn't write it like I
was doing for a C/C++ hybrid _anyway_.

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

Nov 13 '05 #305
On Sun, 19 Oct 2003 00:43:44 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
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.


*Shrug*
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.
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,


You've been told several times.
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.
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 !
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. BTW do you also try to compile with a fortran
and pascal compiler? To be sure?
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++.
Problems don't disappear by qualifying them as QOI.


But its still not a C problem is it?

--
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 #306
On Sun, 19 Oct 2003 00:52:12 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
Mark McIntyre wrote:
<snip enum example claiming ti support this>
I think 'claiming to support' is a bit dismissive? I think my example is
excellent, actually! :-)


Since it demonstrates a nonexistent point. I beg to differ.
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.


That's my point. I think it should be an error.


Then submit a DR to the standards committee. Sheesh.
The benefit, I hesitate to repeat, is the ability to compile my C
program with a C++ compiler as well.


"Benefit" to incorrectly flag errors that don't exist? Shurely shome
mishtake.

--
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 #307
On Sun, 19 Oct 2003 01:27:23 +0200, in comp.lang.c , Irrwahn
Grausewitz <ir*******@free net.de> wrote:
Sidney Cadot <si****@jigsaw. nl> wrote:
Mark McIntyre wrote:

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


Well, it's correct, as opposed to Marks first alternative, but anyway:

Beauty is in the eye of the beholder. :)


indeed, some people reputedly even liked Ford Edsels...

--
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 #308
On Sun, 19 Oct 2003 03:47:38 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
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."


True in abstract, sadly my version is as likely to be the case in
practice.... hence the whole 'don't cast malloc' point.
(Of course, it's the programmer's job to ensure that the
conversion is meaningful.)


quite.
--
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 #309
Mark McIntyre wrote:
[snip]
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.


That's my point. I think it should be an error. Then submit a DR to the standards committee. Sheesh.


Wouldn't stand a chance, since for the time being this would break too
much existing code.
The benefit, I hesitate to repeat, is the ability to compile my C
program with a C++ compiler as well.


"Benefit" to incorrectly flag errors that don't exist? Shurely shome
mishtake.


To flag potential problems. Tell me, do you refuse to use the warning
facilities by your favorite C compiler? If not, why not?

Best regards, Sidney

Nov 13 '05 #310

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...
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...
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
10412
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
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...
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
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.