473,883 Members | 1,663 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
cody wrote:
OK i tried it and:

int i = sizeof (int);
// int j = sizeof int; // invalid in both C and C++
int k = sizeof i;
int l = sizeof (i);
Wrong type. Use size_t for capturing the value yielded by sizeof.
The form of sizeof that gets a type as parameter has to use parantheses,
while the sizeof that gets non-expressions as parameter do not need them.
Wrong. In your example, i is an unary-expression, not a non-expression.

Specifically, the grammar says:

unary-expression:
postfix-expression
++ unary-expression
-- unary-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-name )

(taken from K&R2, p238, since it happened to be on my desk, opened to that
page!)

Note also that sizeof takes an operand, not a parameter.
This seems to be true for both C and C++ compilers (I tried both).


It really is time to stop guessing at this stuff. The C language is defined
by an international standard, not by your apparently random guesses.

--
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 #231
Douglas A. Gwyn wrote:
cody wrote:
The problem is that i believe that my assertions are correct.


Yes, that is a problem.


I hope the sig-monsters are awake.

--
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 #232
Richard Heathfield <do******@addre ss.co.uk.invali d> writes:
cody wrote:
OK i tried it and:

int i = sizeof (int);
// int j = sizeof int; // invalid in both C and C++
int k = sizeof i;
int l = sizeof (i);


Wrong type. Use size_t for capturing the value yielded by sizeof.


It's not entirely unreasonable to use int rather than size_t in this
particular case. The result of the sizeof operator, which is of
course of type size_t, is implicitly converted to type int, which is
virtually certain to be able to hold the result. (I say "virtually
certain" rather than "certain" because I can just barely imagine that
some insanely evil implementer might shove enough padding bits into
type int to make its size overflow an int without breaking
conformance.)

Richard's other criticisms are, of course, dead on.

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #233

On Wed, 15 Oct 2003, Richard Heathfield wrote:

cody wrote:
[Arthur wrote:]
int test(int size)
{
int *new = malloc(size); /* two non-C++isms in this line */
return 1 //*
-1 + 1; /* 0 in C99, 1 in C++ */
}


is the missing semicolon at the end of a block allowed in C?


No, and that wasn't his only mistake.


Whew, I'm lucky I was lazy in responding. :) I completely forgot
about // comments' being legal C99. But your code still has a
bug; under C90, the /**/ comments disappear to create

int foo = 1/;

don't they? So I guess after fixing that, we could throw in a
sizeof('x') for good measure. [ACTUAL TESTED CODE FOLLOWS(!)]
#include <stdio.h>

int test_version(vo id)
{
/* Returns 0 under C90, 1 under C99, and 2 under C++ */

int isnt_c90 = 1 //*
-1 /* 0 in C90, 1 in C99/C++ */
+2 / 2;
int is_cxx = (sizeof('x') == 1); /* not completely guaranteed
* to work, but the best I know
* off the top of my head */
return isnt_c90 + is_cxx;
}

int main(void)
{
printf("%d\n", test_version()) ;
/* gcc -std=c89: 0 */
/* gcc -std=c99: 1 */
/* g++: 2 */
return 0;
}

Now, what silly mistakes have I made *this* time? :-)

-Arthur
Nov 13 '05 #234
In article <Pi************ *************** ********@unix47 .andrew.cmu.edu >
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> writes, in part:
int is_cxx = (sizeof('x') == 1); /* not completely guaranteed
* to work, but the best I know
* off the top of my head */


As you note, this can falsely claim "is C++" if sizeof(int)==1.

A test that does not have this failing -- that *is* guaranteed
to distinguish between C and C++ -- is one that relies on the
differing scope rules. Here is a complete test program.

#include <stdio.h>

struct A { char c; };

int is_cplusplus(vo id) {
struct B { struct A { char c[2]; } b; };
struct A x;

return sizeof x.c == 1;
}

int main(void) {
printf("this was compiled with a %s compiler\n",
is_cplusplus() ? "C++" : "C");
return 0;
}

The trick is that the name "struct A" refers to the *inner* "struct
A" in C, but to the global (outer) "struct A" in C++. (In C++-ese,
x is defined as ::A instead of ::B::A. Thus in C++ x.c is a single
"char", while in C++ x.c is an array of two "char"s.)

This particular difference between the two languages can turn a
correct C program -- one that writes into both bytes of x.c[] --
into an incorrect C++ program when compiled with a C++ compiler.
Thus, even putting aside the obvious syntactic incompatibiliti es
between the two languages, I claim it is dangerous to compile C
code with a C++ compiler. You might overrun arrays, as this
program could do if it assumed it was compiled with a C compiler
(if is_cplusplus() were to write on x.c[1]).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #235
On Wed, 15 Oct 2003 22:17:35 +0200
"cody" <do************ *********@gmx.d e> wrote:

Please don't trim the attributions since it prevents people from seeing
who said what.
int test(int size)
{
int *new = malloc(size); /* two non-C++isms in this line */
return 1 //*
-1 + 1; /* 0 in C99, 1 in C++ */
}


is the missing semicolon at the end of a block allowed in C?


A semicolon is required to terminate every C statement, however in C99
there is no missing semicolon in the above.

HINT: C99 added a form of // commenting.

<snip>
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
Nov 13 '05 #236
Arthur J. O'Dwyer wrote:

<snip>
I completely forgot
about // comments' being legal C99. But your code still has a
bug; under C90, the /**/ comments disappear to create

int foo = 1/;

don't they? So I guess after fixing that, we could throw in a
sizeof('x') for good measure. [ACTUAL TESTED CODE FOLLOWS(!)]


"ACTUAL TESTED CODE"? Isn't that cheating?

--
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 #237
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.
I agree that "C++ has never been a strict superset of any version of C",
but I disagree with your logic. A superset can define new keywords (and
comment operators).


A strict superset can't, if those keywords have names which are not
already reserved for use by the implementation, because adding new
keywords will invalidate existing C programs that happen to use those
keywords as identifiers.

Adding new comment operators can also change the meaning of existing code.
Consider the following program:

int main() {
printf(1//**/2
? "fail\n" : "pass\n");
return 0;
}

On a conforming C89 implementation, this will print "pass",
but on a C++ or C99 implementation, it will print "fail".
However there are many constructs in standard C that
are illegal in C++. One example that comes to mine is:
In C:
void foo(void);
In C++ this will cause a syntax error because C++ requires fully
prototyped functions.


That's not correct either. C++ allows "void foo(void);".

--
Fergus Henderson <fj*@cs.mu.oz.a u> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #238
In article <cl************ ****@plethora.n et>, Chris Hills
<ch***@phaedsys .org> writes
Francis, AFAIK you have absolutely no knowledge of the 8051 other than
what I have told you in various ACCU and BSI meetings.... and that has
been very superficial. It would be best if you did not use it as an
example.

It would also be nice if you avoided assuming that you are my only
source of information.

However one factor often missed is that these days we often use
micro-processors to do things that are note remotely related to a
traditional view of their uses. The growth of digital sound and vision
systems is largely driven by the ability to bring computing power to
tasks that thirty years ago would have been considered as completely
outside the domain of computing.

One interesting point is that in times gone by much effort was put into
developing analogue computing technology in order to improve data
throughput where some loss of quality was acceptable. These days we
develop digital systems with the same motive:-)

I suspect that LSI has changed the world in ways that neither of us
could have imagined in our youth and that most people do not have the
slightest grasp of the extent to which modern technology relies on
computing technology.
--
Francis Glassborow ACCU
If you are not using up-to-date virus protection you should not be reading
this. Viruses do not just hurt the infected but the whole community.
--
comp.lang.c.mod erated - moderation address: cl**@plethora.n et
Nov 13 '05 #239
"Sven Semmler" <sv*********@se mmlerconsulting .com> schrieb im Newsbeitrag
news:cl******** ********@pletho ra.net...
cody wrote:
sorry i don't know the term "dead on". what does it mean?


http://dict.leo.org/?search=dead+on

/Sven ;)

thankx

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

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
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
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
10410
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...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
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.