473,883 Members | 1,688 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 23872
kelseyb wrote:
[snip]


You are making many points that are very similar to Mark's in your two
posts, but from my side I would like to put this thread to rest now,
since it deteriorated into rehashing the same arguments post after post.

So thanks for your posts (read them with sincere interest), I am very
much tempted to provide answers that perhaps could show the merits of my
point-of-view, but I will refrain from doing so since basically all
arguments have already been made in my exchange with Mark.

Best regards, Sidney

Nov 13 '05 #361
On Wed, 22 Oct 2003 06:02:49 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
that didn't mean it was an off-road vehicle,
except in the hospitalisation sense of the word.


So you'll definitely be upgrading to the new model then? :-)

--
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 #362
P.J. Plauger <pj*@dinkumware .com> scribbled the following:
"James Kuyper" <ku****@wizard. net> wrote in message
news:8b******** *************** ***@posting.goo gle.com...
> > PJ we already know you're a heathen, so no need to chime in... :-)
>
> Nice of you to notice. In fact, I've been officially recognized as
> a heathen by the All Catholic Church. It's a point of pride with me.
Congratulations ! How did you win this honor? No one's ever bothered
giving me official recognition. :-(

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. (That marriage lasted less than five years. Tana and I were married in
Manhattan Borough City Hall by a J.P. We'll celebrate our 26th anniversary
in Kona next week with our kids. Go figure.) For the record -- and your C question is?


How can I get officially branded as a heathen too, without (1) marrying
anyone or (2) joining the Protestant Church?

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
Nov 13 '05 #363
"E. Robert Tisdale" wrote:
CBFalconer wrote:
I and, apparently, almost everyone else, thinks that
your malloc casts are ridiculous.
I don't think that they are ridiculous.


I don't know why I bother replying, but without it some dewy eyed
newbie might think you know what you are talking about.
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.


Further nonsense. The languages are different. Neither is Ada
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.


Once more, you display abysmal ignorance. Derived types are not
generally new types. One can define a type by:

typedef enum quality {GOOD, INDIFFERENT, BAD} quality;

and declare items of type quality. They should never hold values
other than those enumerated. The problem is 'how to persuade the
C compiler to verify that'. C is a very poor language for strong
typing.

The ordinal values associated with GOOD, INDIFFERENT, BAD have no
special meaning other than defining an ordering. Things with this
attribute may have the quality GOOD, or BAD, but 42 has no
meaning. Neither does 1, except that C will treat it as
INDIFFERENT, and such usage often indicates an error.
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.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #364
Sidney Cadot wrote:
.... snip ...
Sure, this is not very practical. But it goes to illustrate the
point that leaving the cast to the assignment is presuming too
much. Sad thing (for my argumentation anyway) is that you do
assign the malloc() result in 99% of cases, and even in your
strcpy example there will be an implicit cast to the type of
the format argument. Darn :-)


If you don't assign the result from a malloc() you are guaranteed
a memory leak. I would consider this to be ungood.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #365
Jeremy Yallop wrote:

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

And when fully compliant C99 compilers become the norm, then we'll talk
again. I don't have one, do you?

Brian Rodenborn
Nov 13 '05 #366
CBFalconer wrote:
Sidney Cadot wrote:

... snip ...
Sure, this is not very practical. But it goes to illustrate the
point that leaving the cast to the assignment is presuming too
much. Sad thing (for my argumentation anyway) is that you do
assign the malloc() result in 99% of cases, and even in your
strcpy example there will be an implicit cast to the type of
the format argument. Darn :-)

If you don't assign the result from a malloc() you are guaranteed
a memory leak. I would consider this to be ungood.


Doubleplus ungood, for sure. But just for some theoretical fun....:

#include <stdio.h>
#include <stdlib.h>
{
char B[100], *p;
sprintf(B, "%p", malloc(20));
sscanf(B, "%p", (void **)p);
free(p);
return 0;
}

Best regards, Sidney

Nov 13 '05 #367
Sidney Cadot wrote:
#include <stdio.h>
#include <stdlib.h>
{
char B[100], *p;
sprintf(B, "%p", malloc(20));
sscanf(B, "%p", (void **)p);


Undefined behaviour. Not a particularly good example in favour of
using casts.

Jeremy.
Nov 13 '05 #368
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in message news:<bn******* ***@hercules.bt internet.com>.. .
P.J. Plauger wrote:

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


Assume clock_t is, for a particular implementation, a typedef for
'double'. Then

printf("%g", clock()/CLOCKS_PER_SEC) ;

is correct code for that implementation, but needs to be rewritten as:

printf("%g", (double)clock()/(double)CLOCKS_ PER_SEC);

for portability to other implementations , where clock_t might be, for
instance, an 'int'. Even this more portable form fails in the
techically possible case where clock_t is typedef for an imaginary
type. :-)

Excersize for the student: HOW does it fail? Can it be re-written to
work in all cases?
for C++ compatibility,


I am yet to be persuaded that you need anything other than extern "C" { }
for C++ compatibility.


Examine Annex C of the C++ standard. It's quite possible to write
valid C code that is also valid C++ code, with different meanings.
Using extern "C" is not sufficient to cover those cases.

There's a common misconception that code in an extern "C" block gets
compiled according to the rules of the C language; it does not. An
identifier with external linkage declared as extern "C" is passed to
the linker using C naming conventions. A function or function pointer
whose function type is declared extern "C" uses C interface
conventions. However, the actual code in an extern block gets compiled
using the rules of C++, and can make use of C++ features such as
templates and function overloading (though a function with extern "C"
language linkage cannot itself be part of an overload set).

In particular, for every case listed in Annex C where the C and C++
languages interpret the same valid code differently, it's the C++
interpretation that will be used, which can cause C code to break if
you try to convert it for C++ use just by naively slapping on extern
"C".
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?


As a general rule, end users would tend to be annoyed if using a
library required them to send the compiler output through a "warning
processor". They might end up deciding to use a different library,
that doesn't impose such a burden.
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.


Let me translate his English; it's pretty straight forward.

here.h:
#include "somewhere_else .h"
typedef struct
{
// "... a structure declared here containing a pointer to ..."
their_struct *ptheirs;
// other contents.
} other_struct;
somewhere_else. h:
// " ... a structure declared somewhere else ..."
typedef struct
{
// contents
} their_struct;

there.c:
#include "here.h"
// " ... for which storage is allocated there ..."
void there(ourstruct *ours, size_t N)
{ // ".. 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.
ours->theirs = (their_struct*) malloc(N * sizeof(their_st ruct));

// Other code.
}

some_other_ther e.c:
#include "here.h"
// " ... and freed some other there ..."
void some_other_ther e(ourstruct *ours)
{
// Other code
free(ours->theirs);
}

The one problem that can be caught by the cast of the malloc() return
value is a mis-match between the actual type of "ours->theirs" and the
type used in the type cast. The cost of this technique is that it
merely replaces one opportunity for a silent mis-match with a
different opportunity for an equally disastrous silent mis-match.
However, since the cast and the sizeof are both on the same line, they
are much less likely to get out of sync with each other, than either
of them is to get out of sync with the actual type of "ours->theirs".
Nov 13 '05 #369
Sidney Cadot <si****@jigsaw. nl> wrote in message news:<bn******* ***@news.tudelf t.nl>...
Arthur J. O'Dwyer wrote:
On Tue, 21 Oct 2003, Sidney Cadot wrote:
Arthur J. O'Dwyer wrote:
.... N869 section 6.5.16.1#2, which describes the order of operations
during the assignment:

malloc() is called, and then returns a (void *).
That (void *) is converted to (double *) and assigned to x.

With the cast, we get:

malloc() is called, and then returns a (void *).
That (void *) is converted to (double *) [and then...]
That (double *) is assigned to x.

Same exact thing. No change in executable; no change in value;
no change in type. Just extra verbiage.


I was thinking in terms of how a compiler would handle this: with
casted-malloc, it first changes the type of the void* to double*, after
which it will go and handle double*-to-double* assignment. with
uncasted-malloc, it will recognise void*-to-double* assigment and then
either directly or indirectly (via an inserted cast) generate the same
code, which is a slightly different execution path for the compiler to take.


Yes, if you change the code that is being parsed, you change the
execution path of the compiler. You also change the execution path of
the compiler by inserting space characters and comments. You also
change it when you replace a type with a typedef, or an expression
with a macro that expands into the same expression.

However, with both the casted and uncasted version of the code, you're
telling the compiler to generate code that does exactly the same
thing.
Nov 13 '05 #370

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
9935
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
11137
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
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
10844
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
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...
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.