473,889 Members | 1,455 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
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote:
James Kuyper wrote:
It's not mandatory.
But we *do* expect programmers to exercise *some* discretion when choosing
a C compiler. C compiler developers don't care about the mandates of the
ANSI/ISO C standards. They only care about pleasing their customers. They
conform to the standards only to the extent that doing so pleases their
customers.


Customers, in this case being C programmers, will usually be clued up enough
to demand conformance to appropriate standards. The management who employ
the programmers should also be impressed by compliance to appropriate
standards
Conforming to the ANSI/ISO standards is *not* sufficient to
guarantee that their compilers will be successful.


Not in itself no, but it can be a selling point - particular if your
competitors cannot offer it.
--
Stewart Brodie
Nov 13 '05 #401
>> 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.

dj******@csclub .uwaterloo.ca (Dave Vandervies) wrote 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.)


And I prefer this:
if (a > b and (a > c or a == -1)) ...
over this:
if (a > b && (a > c || a == -1)) ...

This is standard C++, but requires an extra #include in C.

-drt
Nov 13 '05 #402
On Wed, 22 Oct 2003 22:19:12 +0000, Jeremy Yallop wrote:
snprintf solves that problem, anyway. You really want something like
the GNU `asprintf' in this case.


No, you don't ... really. asprintf() isn't just non-standard, it's been
subtly defined differently on a major platform[1] ... and who knows how it'll
be defined if it ever makes it to next C std.

[1] http://www.and.org/vstr/security.html#libcsprintf

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

Nov 13 '05 #403
On Thu, 23 Oct 2003 09:58:49 -0400, James Kuyper wrote:

Nope. But that's because we work according to a coding standard which
prohibits taking advantage of implicit conversions; all conversions must
be the result of explicit casts. That's a bad idea, in my opinion, but


I you really saying you are required to do...

char *foo = "foo";

printf("%c", (int)*foo);

....or is this only for (void *)?

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

Nov 13 '05 #404
Richard Heathfield <do******@addre ss.co.uk.invali d> writes:
Derek Millar wrote:
Well, sure, but as I understand it, the requirement in this particular
situation is to have a single piece of code which compiles under both
C and C++,


But it is this very "requiremen t" which I'm challenging. With the obvious
exception of Mr Plauger (who is shipping a standard library implementation
which must be able to work with both C and C++) and others of his ilk, I am
not convinced that the "requiremen t" is a valid one.

I have a hard time imagining a case where I'd do it myself, I agree. As
I think someone else in the thread pointed out, it tends to make more sense
to compile the C files with a C compiler and the C++ files with a C++
compiler and just put the usual 'extern "C"' lines in the C headers that
need to be shared with C++.

Hypothetically, I suppose it could come up in a project which is
transitioning from C to C++, or in one where some developers know
one language but not the other (though training makes more sense there),
or maybe a case where the implementation language hasn't been finalized.
Plus cases like Mr. Plauger's, of course. None of these seem especially
commonplace.
....
Whether there's a general need for
that sort of code or not is a separate question.


I think it's all part of the same question, BICBW.

I'd say the first is an engineering question and the second is an
ideological question. YMMV.
Derek
Nov 13 '05 #405
In article <lz************ @cts.com>, Keith Thompson <ks*@cts.com>
wrote:
The real problem is that a cast is too blunt an instrument. If there
were an operator that meant "convert a void* value to FOO*", and that
would cause a diagnostic if applied to something of a type other than
void*, it would be perfectly sensible to apply such an operator to a
malloc() call. Unfortunately, all we have is the cast operator, which
says "convert this value to FOO*; I don't particularly care what its
original type is", so it's (usually) safer to depend on the implicit
conversion from void* to any object pointer type.


This is untested:

#define cast(ptr,ptrtyp e) \
(sizeof ((ptr) == (ptrtype) (ptr)), (ptrtype) ptr)

The sizeof operator just checks whether its argument is semantically
legal and then yields sizeof (int), hopefully without producing any
code. Its argument is legal if the original pointer can be compared to
the pointer after the cast. This allows you to cast from and to void*,
and it allows you to cast for example from (const something*) to
(something *).

It disallows casting say from int* to long*, or from a non-pointer type
to a pointer type or vice versa. All of course if I didn't make a
mistake in the macro.
Nov 13 '05 #406
James Antill wrote:
On Wed, 22 Oct 2003 22:19:12 +0000, Jeremy Yallop wrote:
snprintf solves that problem, anyway. You really want something like
the GNU `asprintf' in this case.
No, you don't ... really.


Note the words "something like". I'm not suggesting that he actually
use GNU asprintf, but its approximate behaviour is extremely useful
and saves having to call snprintf twice, which can get a bit tedious.
asprintf() isn't just non-standard, it's been subtly defined
differently on a major platform[1] ... and who knows how it'll be
defined if it ever makes it to next C std.


For these reasons it's probably best to write your own version. Ben
Pfaff posted one a while ago: <news:87******* *****@pfaff.sta nford.edu>.

Jeremy.
Nov 13 '05 #407
James Antill wrote:

On Thu, 23 Oct 2003 09:58:49 -0400, James Kuyper wrote:
Nope. But that's because we work according to a coding standard which
prohibits taking advantage of implicit conversions; all conversions must
be the result of explicit casts. That's a bad idea, in my opinion, but


I you really saying you are required to do...

char *foo = "foo";

printf("%c", (int)*foo);


In principle, yes. In practice, while somebody cared enough about the
concept to write down that ill-conceived requirement, no one seems to
really care much about conforming to it. Therefore, I make things easier
for myself by only worrying about the cases that our compiler produces
warning messages for, which don't include the integer promotions. It
does complain when a function prototype causes an argument to be
implicitly converted to the corresponding parameter's type, and when
assignment causes the right operand to be implicitly converted to the
left operand's type. Both of those cases produce warnings even if the
type being converted is void* -> T*.
Nov 13 '05 #408
Keith Thompson wrote:
.... snip ...
The macros look fine, but the casts are still unnecessary and
potentially dangerous. Why not just

#define NEW(type) \
(malloc(sizeof( type)))


To make it look more like a C++ new, why not:

#define NEW(var) (var = malloc(sizeof *var))
or
#define NEW(var, n) (var = malloc((n) * sizeof *var))

we can still test with:

if (!NEW(diddly, 1)) failon(NOMEM);
else {
/* diddly is allocated, use it */
}

and iff we really want to use it under C++, we can alter the macro
to do the casting. Meanwhile the compilers should protest if var
is not an lvalue.

--
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 #409
In <3F************ ***@saicmodis.c om> James Kuyper <ku****@saicmod is.com> writes:
James Antill wrote:

On Thu, 23 Oct 2003 09:58:49 -0400, James Kuyper wrote:
> Nope. But that's because we work according to a coding standard which
> prohibits taking advantage of implicit conversions; all conversions must
> be the result of explicit casts. That's a bad idea, in my opinion, but

Not bad, horrible. Whoever came up with it had no clue about the value of
implicit conversions.
I you really saying you are required to do...

char *foo = "foo";

printf("%c", (int)*foo);


In principle, yes. In practice, while somebody cared enough about the
concept to write down that ill-conceived requirement, no one seems to
really care much about conforming to it. Therefore, I make things easier
for myself by only worrying about the cases that our compiler produces
warning messages for, which don't include the integer promotions. It
does complain when a function prototype causes an argument to be
implicitly converted to the corresponding parameter's type, and when
assignment causes the right operand to be implicitly converted to the
left operand's type. Both of those cases produce warnings even if the
type being converted is void* -> T*.


Which prompts for the canonical c.l.c example of why casting void pointers
is evil:

int main()
{
char *p = (char *)malloc(10);
return 0;
}

is a perfect example of undefined behaviour in C89. Drop the cast and
a diagnostic is required because an int value (malloc's return value)
is implicitly converted to a pointer value.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #410

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
10785
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
10887
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
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
9603
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
7991
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
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...
1
4644
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
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.