473,883 Members | 1,527 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
While re-reading my post, I discovered at least four typos. Since this
usually annoys the heck out of me in other people's posts: sorry about that.

(This is partially because I'm typing on a laptop in horizontal
position. I will try to better my ways).

-- Sidney

Nov 13 '05 #351
"E. Robert Tisdale" wrote:
My GNU C compiler easily detects the missing declaration for malloc
with or without the cast.
I don't see *any* advantage to omitting the explicit cast.

This is stupid even for Trollsdale. There's no requirement for an
implementation to do the above.


Brian Rodenborn
Nov 13 '05 #352
Default User wrote:
"E. Robert Tisdale" wrote:
My GNU C compiler easily detects the missing declaration for malloc
with or without the cast.


There's no requirement for an implementation to do the above.


There is such a requirement in C99, where calling an undeclared
function is an error (a syntax error, if footnotes are to be
believed).

Jeremy.
Nov 13 '05 #353
On Tue, 21 Oct 2003 02:37:39 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
In between these two instants (at compile time), an expression is alive.
euh, yes. Don't stop taking the dried-frog pills !!! :-)
int *x = (double *)malloc(1000*s izeof(double))


The only error here is in using a poor style.


Look again....


I saw it the first time. Its is merely a "potential problem" as
someone round here would say. :-)
I'd like you to consider why it is that this fragment
gives an incompatible pointer type error, in the context of your earlier
claim "It can't happen any faster than that".
Because you used poor style in the first place. If you'd written the
code properly, the error could not have existed.
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.


I decline to dignify your rudely worded remarks with a response.


Sorry, but I'm getting quite fed up with your silly attempts to
justify this practice by resort to bug reduction. By all means, do it
because you want to cross compile to C++.
That does not answer my question.


Yes it does. You're being obtuse, or stupid, or silly, either is
applicable.


I had to look up obtuse in a thesaurus, which leads me to believe you're
not being nice. Having a debate is one thing, calling names is another.


obtuse:
an angle that is more than 90 degrees; or
someone who's pretending to be stupider than they are.
Not sure either is an insult but YMMV.
"Please", is the proper idiom, in the English language, anyway.


And avoiding the question is just as rude !
--
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 #354
On Tue, 21 Oct 2003 08:11:33 +0200, in comp.lang.c , Sidney Cadot
<si****@jigsaw. nl> wrote:
Mark McIntyre wrote:
ROFL. I'm quite stubbornly refusing to let you get away with blanket
unfounded and unprovable statements you mean.


This makes no sense. Why this weird insistance that C++ could never,
under no circumstance, help to unearth problems in C code that go
unnoticed by a C compiler?


Because, unlike lint, its a C++ compiler, designed to compile a
different language.
Would you use the workshop manual for a VW Polo to fix a Ford Mondeo?
No. But you might use a Haynes VW Polo manual (lint) instead of the VW
regulation issue one (C compiler).
Would you say the same thing of lint-type
programs? They are also not C compilers, and will warn about many types
of potential problems that a C compiler will miss.
Because they're *designed* to do that. Don't use a hammer to insert
screws, or a steel screwdriver to remove live cables.
What "world of difference" would that be? What, in principle, is this
difference?
The one you're refusing to see, and I've explained so many times my
fingers hurt.
As to "I don't", that's find by me. I don't entertain hopes of
convincing you, although I would certainly hope that you wouldn't
dismiss the case I am trying to make out of hand.
I didn't, I read your posts, I considered them and I realised you had
no case.
As to the talking myself out of a corner, that's a bit difficult, not
being in a corner and all.


Its got two sides, one to the left, and one to the right, they meet
behind you and extend down to the floor....
--
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 #355
"Kevin D. Quitt" <KQ**********@I EEInc.MUNG.com> wrote in message
news:tg******** *************** *********@4ax.c om...
On Sat, 18 Oct 2003 19:56:35 GMT, "P.J. Plauger" <pj*@dinkumware .com>
wrote:
And I've never been sorry. A more curious person might wonder why.


Because you've never ported your code to a machine with 16 bit ints and 24
bit pointers.


You must know something about us that we don't. I thought we had.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 13 '05 #356
In article <bm**********@n ews.tudelft.nl> , si****@jigsaw.n l says...
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.


Which indicates one of two things: either a misunderstandin g of the
processes involved, or a probable bug.

On the one hand, we might have something such as:

double *func();
int *x = func();

This is almost certainly a bug, and adding the cast may stop the
compiler emitting a sensible and entirely appropriate warning. On the
other hand:

double *x = malloc(100 * sizeof(*x));

is fine; malloc is defined to return a void *, which is both suitably
aligned for any type _and_ compatible with pointers of other types, such
as double * or char * or int *.

In neither case would adding casts offer any benefit whatsoever. In the
case of, say, malloc, the cast is unneeded and, if present, may prevent
an "incompatib le cast from int to pointer" warning if you've forgottent
to include the relevant header. In the case of the former example, the
only "benefit" would be reducing emitted warnings... but those warnings
are entirely correct; you almost certainly _are_ doing something wrong.
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.
Except that it isn't. It needs no such help, never has.
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.


So? C++ is a different language. Here's the equivalent code in C and
in C++:

int *ptr;
ptr = malloc( 100 * sizeof(*ptr));

int *ptr;
ptr = (int *)malloc( 100 * sizeof(*ptr));

The former is correct C, the latter correct C++. The former will not
compile in C++... because it isn't C++ code. This is comp.lang.c, where
_C_ is discussed; C++ land is down the hall.

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.


Or to differences in the languages. Such as the fact that perfectly
correct C code - which doesn't include pointless casting of malloc -
simply will not compile with a C++ compiler. Then again, it won't
compile with a Delphi compiler, either - probably because it's _C_ code,
not C++ or Delphi 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.


Is the integer compatible with the enum? Recall that C and C++ have
different rules about what is compatible and what isn't. If they're
compatible, why expect a warning? If they're not, that'd be a different
matter. You may _want_ such a warning, and there may be compilers that
will warn on such - or perhaps lint tools - but passing a compatible
type is not something I would generally expect a compiler to be warning
about.

Nov 13 '05 #357
[snips]

In article <bm**********@n ews.tudelft.nl> , si****@jigsaw.n l says...
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.
Easy:

double *ptr = malloc( 1000 * sizeof(*ptr));

You can't possibly convert it any sooner; even adding an explicit cast
simply converts the returned type to a double *... which is exactly what
the assignment is doing. All you're doing by adding a cast is telling
the compiler it shouldn't warn you when the result _should_ generate a
warning - such as when you forgot to include the appropriate header and
malloc ends up with an implicit int return type.
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.


Does it compile in VB? With a Modula-2 compiler? Probably not. Then
again, it is _C_ code, so why should it? Hmm, doesn't even compile in a
C++ compiler, does it? Wonder why. Maybe because it is _C_ code, not
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.


double *ptr = malloc( 1000 * sizeof(*ptr));

Compiles in C++, does it? No? But it's perfectly good C. So either
your C++ compiler is broken, because it won't compile correct C, or the
compiler is working fine, but your expectations are wrong.
BTW do you also try to compile with a fortran and pascal compiler? To be sure?


Is it really needed to aim for ridicule?


Why would these be ridiculous? You're already compiling C code with a
compiler for a different language; why is it somehow less ridiculous
just because that other language happens to superficially resemble C?
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.
Really? How? Oh, by applying C++ rules to things... but that would
force the code to be[come] reasonably correct C++ code; this has nothing
to do with its correctness as C code; C++ and C are different languages.
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.


lint. Not a C++ compiler, which will give you C++-specific warnings and
suchlike, but a C-specific lint tool.
Just out of curiousity: do you consider it good style to pass an integer
literal as an argument to a function expecting an enum?
Generally? No. Why have enums in the first place if you're not going
to use them? However, as far as the compiler is concerned, a 3 is a 3,
whether it's an int or 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?


The compiler is the wrong tool; the IDE (or editor) is. Do a search for
any calls of the function; the parameters being passed will be the items
to examine.

Nov 13 '05 #358
P.J. Plauger wrote:
"Richard Heathfield" <do******@addre ss.co.uk.invali d> wrote in message
news:bn******** **@hercules.bti nternet.com...
Since Mr Plauger is a highly respected figure (and rightly so, IMHO), I
am not prepared to dismiss his opinion lightly, but I am curious to know
the reasons for that opinion. Until then at least, I will of course
continue to recommend that casting malloc is spurious and
counter-productive.
I thought I had given more than one reason, en passant, but here's a quick
review.


Perhaps you did so during that period where few of us could access your
articles, for some config reason or other.
Indeed the first motivation we had for adding casts to malloc
calls was to satisfy a market need to have all our Standard C library
compile either as C or C++.
This "market need" - do you really mean "market demand"? (I can't think of
any particular /need/ for code to compile as both C and C++, but I can
certainly think of ways in which the marketplace might imagine such a
need.)
The C++ Standard (thanks to me) deliberately
permits the C library to have either extern "C" or extern "C++" linkage --
and we have serious customers for both flavors. Having done so, we then
found reasons to make *all* of our C source code compilable as C++.
Well, this is indeed what you have said before, but I am not clear about
what those reasons actually /are/.
Generally I avoid casts for the reason so often given -- they're so strong
that they often hide problems.
Yes, they do.
We add them where required for correctness,
Check...
for portability,
Do you have an example of a cast that is not required for correctness but
which can nevertheless add to the portability of a program?
for C++ compatibility,
I am yet to be persuaded that you need anything other than extern "C" { }
for C++ compatibility.
and to quiet silly warnings.
Wouldn't some kind of warning-processor do the job better? Why pollute the
code with casts that are not required for any other reason, merely to
silence a verbose compiler?
Our
experience over the years is that the last category of casts do indeed
raise the cost of maintenance -- we fix something here and the forgotten
consequences there are masked by the cast, until we discover the bug by
a painful runtime trace.
Right. So why do you keep doing it? :-)
But allocator casts often *help* us find bugs that arise during
maintenance. The classic pattern is a structure declared here, containing
a pointer to another structure declared somewhere else, for which storage
is allocated there, and freed some other there. That's why we allocate N
times the size of the thing we really want, cast the resultant pointer to
a pointer to that type, and store it in what should be a compatible type
of pointer. We've had the compiler inform us of bugs in both size and
pointer types as the code changes under maintenance and enhancement.
I've tried to follow your English explanation, and I can't see anything
terribly difficult or esoteric about what you're doing that would justify a
malloc cast, so presumably I have misunderstood. Could you give us a
concrete C example instead, please? Thanks.
In our environment, bugs like failing to include stdlib.h get found and
fixed in the first pass or two of code writing.
In mine, it's always in the first pass (because, of course, I get a
diagnostic).
We generally perform
*many* passes over our code during development, and develop a companion
set of tests. So the kind of bugs masked by casts on malloc are cheap
to fix, while the kind exposed by such casts are much more expensive.


Well, I thank you for this explanation, but it doesn't actually explain
anything. For example, could you please give an example of "the kind [of
bugs] exposed by such casts [on malloc]" that are otherwise so expensive?

--
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 #359
Mark McIntyre wrote:
Would you use the workshop manual for a VW Polo to fix a Ford Mondeo?


No, but I wouldn't use it to fix a VW Polo either. The only appropriate fate
I can think of for a VW Polo is to be fed into one of those crushing
machine things (where it would last five seconds, max).

Yes, I had a VW Polo, thanks for asking. No, it couldn't go up hills, and
would stall if you insisted that it try. No, it wasn't too happy about
corners. No, it didn't like motorways. It didn't even like driveways. For a
car, it was perhaps disproportionat ely scared of any surface remotely
resembling a road. And no, that didn't mean it was an off-road vehicle,
except in the hospitalisation sense of the word.

I'm tempted to say it was the biggest heap of &*$£$^£ I'd ever driven - but
it wasn't. It was, in fact, the smallest.

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

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
9791
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
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...
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
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...
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.