473,473 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Create 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(function
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.moderated - moderation address: cl**@plethora.net
Nov 13 '05
687 22759
Dan Pop wrote:
In <cl****************@plethora.net> "cody"
<do*********************@gmx.de> writes:
is "const float PI=3.14" possible in plain C?


If you're not aware of the basic standard C features, what makes you
think that you're qualified to participate to this discusion?


No qualification is required for participation in Usenet discussions in
general[1] or comp.lang.c discussions in particular.

Having said that, cody provides a good case for introducing such a
qualification.

[1] There are occasional exceptions, such as the mildly arcane qualification
in the scary devil monastery (I won't give away the secret, but basically
anyone who /can/ post there is, de facto, qualified to post there).

(I presume a.s.r still requires this trick?)

--
Richard Heathfield : bi****@eton.powernet.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 #101
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<PM*****************@newsread4.news.pas.earth link.net>...

<snipped rather large post concerning trollish behaviour>

There. I feel better now. :-)


<grin> do you, then ? a really really *really* small part
of me wants to type in "so, what was your C question?" :-)

goose,
high on sugar, feeling silly right now
Nov 13 '05 #102
"goose" <ru**@webmail.co.za> wrote in message
news:ff**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<PM*****************@newsread4.news.pas.earth link.net>...
<snipped rather large post concerning trollish behaviour>

There. I feel better now. :-)


<grin> do you, then ? a really really *really* small part
of me wants to type in "so, what was your C question?" :-)


OK, I'll bite:

Did anybody here [C] that [C]hicago [C]ubs game
yesterday? What a [C]ontest! A [C]lash of Titans.

The opposing [C]atcher [C]rushed a three-run homer,
[C]ausing his team to [C]ome [C]loser to victory.
[C]ommentators [C]alled it a [C]rucial at-bat.
It seemed to [C]ow the formerly [C]heering home
team [C]rowd.

A [C]enter fielder [C]omitted an error, allowing a
[C]rit[C]al run to s[C]ore.

The [C]losing pit[C]her made a [C]omplaint about
the umpire's De[C]ision [C]on[C]erning a pit[C]h he
[C]onsidered a strike. "You [C]an't [C]!" he [C]laimed.

The opposing team managed to [C]ling to their lead,
[C]lapping ea[C]h other on the ba[C]k and [C]elebrating
after the [C]lose of the game.
Yes, I'm trying to be [C]lever and [C]reative, as
you [C]an [C], although I'm probably [C]ourting
[C]ondemndation by [C]ranky [C]oders, who might
demand [C]essation or [C]loset me in their killfiles
without [C]omment.

:-)

-Mike
Nov 13 '05 #103
Micah Cowan wrote in article <m3************@localhost.localdomain>:
A Perl shell has been in existence for some time now.

http://www.gregorpurdy.com/gregor/psh/


Well, hush my mouth. Though I will say development on it appears sporadic
and slow. Not something I think I would consider using though.
--
Todd Stephens
ICQ# 3150790
"A witty saying proves nothing." -Voltaire
Nov 13 '05 #104
Richard Heathfield <do******@address.co.uk.invalid> wrote:
Dan Pop wrote:

[1] There are occasional exceptions, such as the mildly arcane qualification
in the scary devil monastery (I won't give away the secret, but basically
anyone who /can/ post there is, de facto, qualified to post there).

(I presume a.s.r still requires this trick?)


Yes.

Richard
Nov 13 '05 #105
"cody" <do*********************@gmx.de> wrote in message
news:bm************@ID-176797.news.uni-berlin.de...
that's what i call an answer :)
First, I will initially take at face value your statement
that you are not trolling. Let's see what happens after
you read the following:

I'm writing this because you probably do not realize
that Mr. Klein is one of the select few people here
who are the most highly qualified to help people to
learn and work with with the C language, as well as
to explain its various strengths and weaknesses, and
to help you decide if C is the most appropriate tool
for a particular task.
i didn't know who he was


A good reason to "look before you leap" :-)
i only knew how he reacted to my
question and his answer seemed to me a bit aggressive.
Many new visitors here get that impression.
People here have a wide variety of personalities.
Try to see past that, and I think you'll find this
place a good source of quality information.
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.
Jack replied as he did because he *knows* that:

1. C does not assign an attribute of "normal" or "abnormal"
to functions.

2. C does not define anything called a "static method" or a
"method".


i mean't "why C instead of C++". i assumed all C programmers would use C++


Why?
and so i said that this is no problem since in C++ they cann still use
c-functions
Nobody said that using C++ is a problem. Some said that
they're unable or unwilling to use it, for various reasons.
or static functions as they are the same as c-functions, basically.
Functions declared as 'static' share the same characteristics
in C and C++, with one exception:

C++ defines a construct 'static member function' which has
no counterpart in C.

iam sorry if i didn't made that clearer.
6. C does indeed specify a keyword 'const' and its effect
when applied. A constant can also be expressed with a
macro.
i didn't knew that.


Again, "Look before you leap" :-)
Another logical question, again probably designed to
cause to to stop and think about what you wrote.
No personal attacks. (Despite the belief to the
contrary by many, ignorance is not a character flaw,
it's simply a lack of education about one or more
subjects, easily rectified, and without any reason
for shame or embarrassment.)
iam not an ignorant.


"Ignorant" is not a noun. It is an adjective, used to
describe a person's level of knowledge about a given
subject. As in, "I'm ignorant of the exact arrival
time of the train, since I don't have a schedule."
Or, "I'm ignorant about auto repair, I've lever learned
it." "Ignorant" means "Don't know."

Ignorance is not a character flaw. But in my opinion,
denial of it when it exists (which is what you seemed
to be doing), is.
why do you think i asked this question?
To reduce your ignorance about C and C++,
I would hope.
i only wanted reasons why people still use C. ok now i have got enough
reasons.

- C is simpler than C++
- some people don't like OOP
- some people don't want to learn OOP
- some projects don't need OOP
OOP is not the only reason people use C++. C++
can be used with many other programming styles.

So make those last three:
- some people don't like C++
- some people don't want to learn C++
- some projects don't need C++
- some platforms dosn't provide a proper C++ compiler.

i didn' know that i would create such a large discussion.
Now you know. :-)
Or is your wisdom to be
> inferred by your lack of proper capitalization, punctuation, and
> grammar?
Perhaps this remark is justified, perhaps not. It seems
that your irrefutable ignorance about C, combined with
your expression of conclusions without premises might
have caused him to associate your nonfluency with English
with your level of wisdom.

I can understand this reaction, since when you wrote your
first post, (in this English-speaking newsgroup), you did not
indicate that English is not your native language, and
unfortunately, a significant number of people whose native
language *is* English post here with spelling, grammar,
etc. far worse than yours.


so what do you advise? should i write in the subject of my next posting:

"warning! german poster with probably wrong capitalization, punctuation

and grammar"
Actually, yes, something like that. But keep the subject
line only about the actual question. But then in the body
of your message, write a short note at the top:

"My native language is not English, please excuse errors,
and ask if my message is not clear."

Many other non-English speakers post here, and this is
what most of them do.

If you post here very long, people will get to know you,
and this 'warning' will not be necessary every time.
The content of your post combined with the poor English
probably caused him to believe you were an American
or British troll.
i didn't know that my english is so bad. i would be very grateful if
somebody give me a hint what is wrong with my grammar.


Actually, after reading this, I believe your grammar seems
to have already improved. However, your capitalization needs
much work, though. :-)

Compare:

I didn't know that my English is so bad. I would be very
grateful if somebody gave me a hint about what is wrong with
my grammar.

You don't need to be perfect, nobody is. Just do the best
you can.
I understand very little German, but my few halfhearted
attempts to learn it quickly informed me that many more
words are capitalized in German than in English; it seems
that every noun is capitalized (only my impression, I'm
not certain.)
that is correct all nouns, proper names and beginnings of a sentence are
capitalised.


In English, capitalize the first word of every sentence,
and all pronouns (for example "I") and proper nouns.
If your defense of your English is that
you're German, I would have expected too many capital
letters, not none at all. :-)
you underestimated my lazyness :-[=]


Yes, sometimes I get lazy, too.

My brief 'learning' experiences with German also indicates
that it uses punctuation as well. Is it true that the
only punctuation characters used consistently are periods
and apostrophes, and that commas are optional, as your
messages seem to show?
some commas in german are optional.


English has firm rules about commas, but hardly anyone
understand them all or agrees about them. I try to
use them where, if I were speaking, I would pause.
It seems to work for me.
Is it true that sentences are begun in lower case?

neither in english nor in german but my shiftkey is broken.
i brough is to the workshop last week but it is still not ready :)
But how did you write "C", "C++", "OO", and "OOP" in
your messages?
1. Why do you seem to feel that OOP is the solution to
all programming issues? Have you blindly believed
the 'mass media'?
no, but you can use C++ without programming OOP sinc C++ is a hybrid
language
which supports various programming paradigms, including structured,oop,
functional and more.


Yes. But then why did you write above:
i only wanted reasons why people still use C. ok now i have got enough
reasons.

- C is simpler than C++
- some people don't like OOP
- some people don't want to learn OOP
- some projects don't need OOP
Three out of four imply that C++ == OOP and nothing else,
which is simply not true.

So it seems to me that either you still believe this,
or have changed your mind.

By the way, C++ does not have direct support for functional
programming. What you probably mean is 'procedural programming'.
2. OOP can be done in virtually any language. Why do
you feel that using a given language's available features
to implement OOP is somehow 'fake'?
oop need language support at least to a certain level.


No. Whatever built-in support is not there can be
written using existing language features in virtually
any language. It could even be done in assembly language,
especially one which has macros, if you have enough time. :-)
when people programm
oop in C then it is certainly faked.
No. They use the language features which are available
to program in whatever paradigm they want. This does
not make it 'fake'. C++ is often preferred when doing
OOP, because of its built-in features which support it,
and help prevent making mistakes.
3. Why do you believe that the insertion of a pointer to
a function into a structure causes the use of that
structure and its function pointer member(s) to become
a component of OOP or OOP itself?
it was just an example how some people fake oop in c.


It's not 'fake'. Also, a function pointer inside a struct
can be (and is) used for other things besides OOP.
4. Are you unaware of the several other concepts and
techniques which comprise OOP?
yes. i have good knowlegde about c++,c# and java. a OO-language needs
classes,ctors,dtors,virtual,abstract,static methods and access modifiers.


Some of those things people will say must exist as built-in
features in order to call a language a "true" or "pure" OO
language. There is always much debate about this, which I
doubt will ever result in any consensus.

But all of those concepts can be implemented in any language
at all. It often requires more work, but it can be (and is)
done.
i consider operator overloading as optional.
It's a very useful tool, but is not an OO concept.
I also often see it overused and abused.

does C++ have a concept of sealed classes? that are classes which cannot be subclassed.
No. It doesn't need them. If you want to talk about
that further, post a question about it to comp.lang.c++

Many others have already asked about and discussed this
issue in that newsgroup, try reading the older messages
about it.
Why do you believe that C++ is the only language which
has features and constructs which directly support OOP?
surely not. it was just an example cos c++ is the successor of c.


Not really. C++ was derived from C, but is not at all
intended to replace it.
You probably have a tool box in your garage. What's
inside? Just a hammer? Just a screwdriver? I suspect
it contains a variety of useful tools. This concept
does not disappear in the programming world.
thats what i meant. why use a tool or another when you have a tool which
combines both?


How large or heavy is the combined tool? How much
does is cost? I'd use the easiest to use tool that
does the job. C++ is a very large language compared
to C, and much more difficult to learn.
why use C when you can use C++ which contains C? thats what i meant.
Another misconception. C++ does *not* contain C. It has
many similar things, but many of them which *look* exactly
the same, will *behave* differently in each language, often
very subtly. This misconception is a source of many bugs
and incorrect programs (and arguments. :-) )
you can
use c++,
nobody will force you to use its additinal features.
But you must use the language itself, which is *different*
from C. The C standard library functions are all available,
but that's not the same thing as the *language*, which is
*not* the same.
prove that my thaughts are illogical.
I believe I've done that above. I've done this with the
intention of helping you. I'm curious as to how you will react.


iam indeed grateful as you pointed out that my question was misunderstood
here.


Perhaps. But we all know that you have misunderstood what
C and C++ are and are not. We tried to tell you this.
i was wondering why some people didn't understand it, now i know why.
It doesn't really matter why, but you didn't understand
about C *or* C++. We tried to tell you this.
Are you saying that when a programming language reaches a
certain age it becomes obsolete or 'unreasonable to use'?
Why?
no, i'm not saying that.


Your previous comments seem to indicate otherwise.
Have you never considered the *domain* of a particular
language? Are you unaware of the concept of "existing code
base?" Simple economics?


nobody will throw away C. it still exists in C++


No, absolutely not.
as C++ is fully backward
compatible
No, absolutely not.
(at least C94 if iam correctly informed)
You have not been correctly informed.
Would you have people throw away perfectly good code
which *already performs its task satisfactorily*
and write it all over again from scratch? Expend the
resources for design alterations often necessary when
moving to a new language? For testing and debugging?
For the extra hardware probably required for the necessary
"run in parallel" period? In a pointless, misguided quest
to be "modern?"
surely not.


Your previous comments seem to indicate otherwise.
Are you suffering from the misconception that any given
single language is or can be the solution to all programming
issues?
surely not.


Your previous comments seem to indicate otherwise.
If you want to discuss or learn about C, this is the place.
If you want to criticize it or compare it with other languages,
this is not the place.
i wanted to learn about C why people still use it and now i know why :)


Much more than you wanted to hear, I suspect. :-)
There. I feel better now. :-)
me to..

now i know why iam always misunderstood here: it certainly is my bad

grammar :-)


That is only a small part of it. Most of us understood
you well enough to know what you were saying. You *definitely*
did *not* understand what C and C++ are and are not.
That's not a crime, or anything to be ashamed about,
all you need to do is learn. The best in the business
read and post here, and you can learn much about C from
them. I certainly have, and continue to learn more every
day. The same is true about C++ in the newsgroup comp.lang.c++

Good luck, and have a nice day.

-Mike

Nov 13 '05 #106
Sidney Cadot <si****@jigsaw.nl> wrote in message news:<bl**********@news.tudelft.nl>...
I can't answer for people in general of course, but as a moderately
able C programmer with a thorough dislike of C++ I can try to
explain what my motives are.

<snip>

That was an excellent response, thank you.

For my current work (programming for an embedded device), use of C++
over C is really a matter of notational convenience. I turn off
exceptions and I do not use templates save for one trivial vector
class (hand-written, not STL).

By notational convenience I mean,

(1) I don't need to say self->data, I can just say m_data. It doesn't
sound like a big deal, but all that s-> clutter really adds up.
Applications for this device cannot use static data, so every
piece of data must come from a struct or class.

(2) The ARM CPU doesn't have floating point. It is an enormous
advantage to define my own fixed-point class with +, -, *, /, etc
operators.

(3) Virtual functions are used but not common. In this regard I trust
my C++ compiler. There is very little difference in code size. I
always know which virtual functions are overridden by which
subclasses so it's just a "distributed switch statement".

(4) I get a warm, fuzzy feeling using socket.open() verses
My_Library_Socket_open(socket). You could call this a straw man,
but I am especially careful about name clashes. The alternatives
are (a) to be not so careful or (b) to rig function pointers
inside structs. I don't like either.

(5) 'extern "C"' can be used if you want an application such as
Mathematica to call into your C++ library. In fact, that's
exactly what I'm doing.

What is your opinion on using a limited subset of C++, if only for
convenience?

Jeff
Nov 13 '05 #107
> "Ignorant" is not a noun. It is an adjective, used to
describe a person's level of knowledge about a given
subject.
In german there "Ignorant" can be used as noun or adjective.
In English, capitalize the first word of every sentence,
and all pronouns (for example "I") and proper nouns.
i know, its just my lazyness which hinders me to do that :)
neither in english nor in german but my shiftkey is broken.
i brough is to the workshop last week but it is still not ready :)


But how did you write "C", "C++", "OO", and "OOP" in
your messages?


magic :)
No. Whatever built-in support is not there can be
written using existing language features in virtually
any language. It could even be done in assembly language,
especially one which has macros, if you have enough time. :-)
i disagree on that. how can you make sure that all data is properly
encapsulated if
the language provides no support?
It's not 'fake'. Also, a function pointer inside a struct
can be (and is) used for other things besides OOP.
i know
thats what i meant. why use a tool or another when you have a tool which
combines both?


How large or heavy is the combined tool? How much
does is cost? I'd use the easiest to use tool that
does the job. C++ is a very large language compared
to C, and much more difficult to learn.


the new tool is very heavy and hard to use, it has many buttons and if you
press the wrong one the whole thing blows up. that's C++.
By the way, C++ does not have direct support for functional
programming. What you probably mean is 'procedural programming'.


not C++ as language, but the STL has many functions/functors which are used
for the functional programming paradigm.
the "repeat" function is an example.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #108
"cody" <do*********************@gmx.de> wrote in message
news:bm************@ID-176797.news.uni-berlin.de...
"Ignorant" is not a noun. It is an adjective, used to
describe a person's level of knowledge about a given
subject.
In german there "Ignorant" can be used as noun or adjective.


I wrote my message in English.
In English, capitalize the first word of every sentence,
and all pronouns (for example "I") and proper nouns.


i know, its just my lazyness which hinders me to do that :)


I think you'll find that you will be taken much
more seriously if you make the effort to write
correctly. Around here, laziness is not well
received.
neither in english nor in german but my shiftkey is broken.
i brough is to the workshop last week but it is still not ready :)
But how did you write "C", "C++", "OO", and "OOP" in
your messages?


magic :)


No, you've been caught in a lie. Just admit it,
apologize, and perhaps people will take you seriously.
No. Whatever built-in support is not there can be
written using existing language features in virtually
any language. It could even be done in assembly language,
especially one which has macros, if you have enough time. :-)
i disagree on that.
how can you make sure that all data is properly
encapsulated if
the language provides no support?


Most programmers use their brains, and don't
let the language do all their thinking for them.
It's not 'fake'. Also, a function pointer inside a struct
can be (and is) used for other things besides OOP.
i know


You know it's not 'fake'? Then why did you call it
'fake' *two* times?
thats what i meant. why use a tool or another when you have a tool which combines both?
How large or heavy is the combined tool? How much
does is cost? I'd use the easiest to use tool that
does the job. C++ is a very large language compared
to C, and much more difficult to learn.


the new tool is very heavy and hard to use, it has many buttons and if you
press the wrong one the whole thing blows up. that's C++.


So don't use it. But your first message was claiming
that people should not use C and use C++ instead.

I use both C and C++ and have successfully written
many programs with them. Some I have written using
a combination of both. Nothing "blows up".
By the way, C++ does not have direct support for functional
programming. What you probably mean is 'procedural programming'.
not C++ as language, but the STL has many functions/functors which are

used for the functional programming paradigm.
If you really think so, post a message (not here), but
at comp.lang.c++ and tell me what they are.
the "repeat" function is an example.


There is no 'repeat' function in C++ (or in C either).

But if you want to talk about C++, here is not the place.
Go to comp.lang.c++ to discuss C++. But I'll warn you
that the most expert C++ people in the world are there,
and know if what you say is right or wrong. Much of
what I learned about C++ I learned from them.

I suggest you start there by *asking questions* not
*telling* people about C++, since you obviously have many
misconceptions about it.

But be sure to read their FAQ first.
-Mike
Nov 13 '05 #109
> > In german there "Ignorant" can be used as noun or adjective.

I wrote my message in English.


I just wanted to say that in german it can be used as noun, too.
> neither in english nor in german but my shiftkey is broken.
> i brough is to the workshop last week but it is still not ready :)

But how did you write "C", "C++", "OO", and "OOP" in
your messages?


magic :)


No, you've been caught in a lie. Just admit it,
apologize, and perhaps people will take you seriously.


you don't understand humour, do you?
No. Whatever built-in support is not there can be
written using existing language features in virtually
any language. It could even be done in assembly language,
especially one which has macros, if you have enough time. :-)


i disagree on that.
how can you make sure that all data is properly
encapsulated if
the language provides no support?


Most programmers use their brains, and don't
let the language do all their thinking for them.


then try to programm a fully functioning OOP application in pure C.
it is impossible to make sure no one can unintentional access private
variables.
It's not 'fake'. Also, a function pointer inside a struct
can be (and is) used for other things besides OOP.


i know


You know it's not 'fake'? Then why did you call it
'fake' *two* times?


storing a function pointer in a struct is commonly used by C programmers.
But i noticed that some programmers abused this to fake OOP features.
the "repeat" function is an example.


There is no 'repeat' function in C++ (or in C either).


my mistake, i thought there was. however there is a foreach function which
has
a bit of functional programming and there is a header file which name is
<functional>.
--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #110
On 06 Oct 2003 18:50:21 GMT, Douglas A. Gwyn <DA****@null.net> wrote:
cody wrote:
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.


There is both a speed and size penalty for using C++ where
pain C would do. The penalty isn't as bad as it used to be.

^^^^

I usually think of C++ as being 'painful C' myself. ;-)

Dave
--
You'll need to kill a tree to mail me.
Nov 13 '05 #111
Dave Von Pless wrote:
On 06 Oct 2003 18:50:21 GMT, Douglas A. Gwyn <DA****@null.net> wrote:
cody wrote:
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.


There is both a speed and size penalty for using C++ where
pain C would do. The penalty isn't as bad as it used to be.

^^^^

I usually think of C++ as being 'painful C' myself. ;-)

Dave


To be honest, I started programming with C++, and quite often think of C as
the more painful to use for many things. I guess it just depends on which
direction your coming from. Kind of like when country boys see the city as
a rude, dirty, and corrupt while the city boys see the country as
backwards, dirty, and twisted.

Sean

Nov 13 '05 #112
cody wrote:
then try to programm a fully functioning OOP application in pure C.
it is impossible to make sure no one can unintentional access private
variables.
Well, the same is the case in C++. I hope not to be chastized too hard
by the crowd here for showing some C++ code but here you go:

#include <iostream>

class YadaYada {
private:
int a;
public:
YadaYada() { a=0; }
void showme() { std::cout << a << std::endl; }
};

int main()
{
YadaYada y;
y.showme();
*(int *)&y=1;
y.showme();
return 0;
}

....Now compare this with some C code that tries to do member hiding:

#ifdef INTERNAL
#define PRIVATE(x) x
#else
#define PRIVATE(x) this_is_private_do_not_touch_me_ ## x
#endif

struct YadaYada {
int PRIVATE(a);
};

Sure, the C way is clunky at best. My point, however, is that both in C
and C++ it is quite possible to circumvent the measures taken for hiding
private data; in both of the examples shown above you would simply have
to be malicious to do it. If you're looking for OOP languages with truly
shielded private variables, you should be reading up on programming
languages instead of ascribing properties to C++ that it doesn't have.
my mistake, i thought there was. however there is a foreach function which
has a bit of functional programming and there is a header file which name is
<functional>.


Pardon me if I'm wrong, but you truly come across as if you haven't got
a clue as to what you are talking about. Perhaps you care to explain
what exactly it is you mean by 'functional programming' - we may both
learn a thing or two.

Then again, this kind of discussion should perhaps be rerouted to
comp.lang.functional - might I also suggest a fitting debut: "Why do
people still use Lisp? ML is so much better..."

Nov 13 '05 #113
Jeff Mitchell wrote:
That was an excellent response, thank you.
Why thank you. That was written at a stage, of course, where I thought
that cody asked his question in order to learn instead of {t|pr}each.

You provide some good reasons why C++ has notational (but no less real)
advantages over C, I think. The important thing in my opinion is to make
an informed decision on ones language of choice for tackling a certain
problem, instead of just going with the tide - which nowadays probably
favors C++ over C. I can surely imagine that using C++ is a viable
option in many circumstances, especially if you limit yourself to the
subset of the language you understand, and understand the possible
ramifications with regard to portability etc.

I especially was interested in your fifth point:
(5) 'extern "C"' can be used if you want an application such as
Mathematica to call into your C++ library. In fact, that's
exactly what I'm doing.


I know that this is quite possible, but for my current project we
refrained from doing this for lack of information about portability.
Yes, we could get it to work using gcc/g++ on Intel/Apple, but our
library also has to work on HP-UX, Solaris, AIX, SGI, ..., with their
proprietary compiler suites.

One testimony to C portability is that this has worked out pretty well
(with something in the order of 100,000 lines of code). There's quite a
thrill in getting a report of a successful HP-UX compile out of the
blue, when you haven't actually tested on such a machine!

(Then again, reading the previous sentence, I think the most important
conclusion is that I need to get out more and get a life outside
computers ;-))

Best regards,

Sidney Cadot
The Netherlands

Nov 13 '05 #114
Sidney Cadot wrote:

<snip>
...Now compare this with some C code that tries to do member hiding:

#ifdef INTERNAL
#define PRIVATE(x) x
#else
#define PRIVATE(x) this_is_private_do_not_touch_me_ ## x
#endif

struct YadaYada {
int PRIVATE(a);
};

Sure, the C way is clunky at best.


Well, that way is. What about this way? Here's an extract from one of my
headers:

typedef struct TCPi_ TCP;

Beat that for data hiding!

(Yes, you can still defeat it maliciously, e.g. with an unsigned char *
pointer or with memset, but (unless you were simply destroying existing
values) you'd have to know what the data items are for, how big they are,
and which order they are in, and the visible code gives you no hints
whatsoever).

--
Richard Heathfield : bi****@eton.powernet.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 #115
Richard Heathfield wrote:
#ifdef INTERNAL
#define PRIVATE(x) x
#else
#define PRIVATE(x) this_is_private_do_not_touch_me_ ## x
#endif

struct YadaYada {
int PRIVATE(a);
};

Sure, the C way is clunky at best.

Well, that way is. What about this way? Here's an extract from one of my
headers:

typedef struct TCPi_ TCP;

Beat that for data hiding!


Yes, good point.

But suppose you want to have some private and some public members, I
think you're stuck with a variation of what I showed (a feeble excuse
for my clumsy example, but still a slightly valid point I think).

This touches on an interesting notational point with regard to C++
syntax: you are forced to expose both private and public members in the
source code of the declaration of the class. Something similar with
Java, where declaration and definition coincide. Your are basically
forced to use a postprocessor on the source to be able to present a
version that is not cluttered with internals (e.g. doxygen for C++ or
javadoc for Java). I've always considered that to be bit untidy.

Regards,

Sidney

Nov 13 '05 #116
> Well, that way is. What about this way? Here's an extract from one of my
headers:

typedef struct TCPi_ TCP;

Beat that for data hiding!

i don't understand what you mean with that.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #117
Ben Pfaff wrote:
#ifdef INTERNAL
#define PRIVATE(x) x
#else
#define PRIVATE(x) this_is_private_do_not_touch_me_ ## x
#endif

struct YadaYada {
int PRIVATE(a);
};
That's only valid if you don't mind invoking undefined behavior.
From C99 6.2.7:

Moreover, two structure, union, or enumerated types declared
in separate translation units are compatible if their tags
and members satisfy the following requirements: If one is
declared with a tag, the other shall be declared with the
same tag. If both are complete types, then the following
additional requirements apply: there shall be a one-to-one
correspondence between their members such that each pair of
corresponding members are declared with compatible types,
and such that if one member of a corresponding pair is
declared with a name, the other member is declared with the
same name.


Type-compatibility may not be an issue here (I'm not sure). It would
certainly be illegal to include the YadaYada definition twice in the
same program, once with INTERNAL defined, once with INTERNAL not defined.

However, in the context of data hiding this idiom (with the YadaYada
declaration in a header file) would be used once to compile e.g. a
library (with INTERNAL defined, providing easy access to the members of
the YadaYada type from within the library code); next, a program using
the library (including the header file containing the YadaYada
declaration, with INTERNAL not defined) would have no access to the
members marked PRIVATE (except by advertantly circumventing the name
mangling).

On the question of whether the scheme layed out above is guaranteed to
work, let's put this question in program form:

---

#include <stdio.h>

struct A {
int tom;
int dick;
int harry;
};

struct B {
int tom;
int george;
int harry;
};

int main(void)
{
struct A a;

a.dick=3;

/* will this print 3, guaranteed? */
printf("%d\n", ((struct B *)&a)->george);

return 0;
}

---

I'd like an expert opinion on this... There are limits to what a
compiler may do to the fields in a struct, I would be curious to know if
these limits are strong enough for the above program to have
well-defined behavior (and thus print '3') ?

Best regards,

Sidney Cadot


Nov 13 '05 #118

"cody" <do*********************@gmx.de> wrote in message
news:bm************@ID-176797.news.uni-berlin.de...
Well, that way is. What about this way? Here's an extract from one of my
headers:

typedef struct TCPi_ TCP;

Beat that for data hiding!

i don't understand what you mean with that.


To me, it means you do not understand at all what
"Object oriented programming" means, despite your
attempts to indicate otherwise.

-Mike
Nov 13 '05 #119
"cody" <do*********************@gmx.de> wrote in message
news:bm************@ID-176797.news.uni-berlin.de...
In german there "Ignorant" can be used as noun or adjective.
I wrote my message in English.


I just wanted to say that in german it can be used as noun, too.
> > neither in english nor in german but my shiftkey is broken.
> > i brough is to the workshop last week but it is still not ready :)
>
> But how did you write "C", "C++", "OO", and "OOP" in
> your messages?

magic :)


No, you've been caught in a lie. Just admit it,
apologize, and perhaps people will take you seriously.


you don't understand humour, do you?


Certainly I do. Most people I know tell me I have
an extraordinary sense of humor. But I fail to see
any humor in this. Perhaps simply a "cultural
difference." Whatever, I won't waste any time
debating it.
> No. Whatever built-in support is not there can be
> written using existing language features in virtually
> any language. It could even be done in assembly language,
> especially one which has macros, if you have enough time. :-)

i disagree on that.
how can you make sure that all data is properly
encapsulated if
the language provides no support?
It does provide it. What do you mean by "properly"?

struct data
{
int details;
};

The value 'details' is properly encapsulated inside
the struct type 'data'. This encapsulation could
indeed be corrupted via making coding errors, but
this does *not* mean the encapsulation is 'improper'.
Most programmers use their brains, and don't
let the language do all their thinking for them.


then try to programm a fully functioning OOP application in pure C.


I certainly could, but have never had any reason to do so.
I suspect that some people actually have done this. I have
no motivation to spend the necessary time on it, but perhaps
if someone were to pay me to do it....
it is impossible to make sure no one can unintentional access private
variables.
The existence of the possibility of coding errors does
not preclude a program from being expressed with OOP.
A language's enforcements of OOP concepts is a very
useful tool, but need not be present for a program
to be expressed using OOP.
> It's not 'fake'. Also, a function pointer inside a struct
> can be (and is) used for other things besides OOP.

i know


You know it's not 'fake'? Then why did you call it
'fake' *two* times?


storing a function pointer in a struct is commonly used by C programmers.


Yes, it is used for a wide variety of purposes, one of which
could be to implement OOP.
But i noticed that some programmers abused this to fake OOP features.
It's *not* fake. Specialized language support (as in
C++ for example) is not a prerequiste for using that
language to write OOP programs.
the "repeat" function is an example.


There is no 'repeat' function in C++ (or in C either).


my mistake, i thought there was.


I strongly suggest you research these issues before
making such statements in the future.
however there is a foreach function which
has
a bit of functional programming
No. 'for_each()' is simply a function which iterates
through a sequence, and applies a function to each
member of that sequence. It's a generalization of
a simple 'for loop', designed to be useful with
the standard library 'container' abstraction.
Nothing at all to do with 'functional programming'.

and there is a header file which name is
<functional>.


Which has nothing to do with 'functional programming',
("Do not judge a book by its cover.")

Again, the C++ issues you mention should be discussed
in comp.lang.c++, not here.

-Mike

Nov 13 '05 #120
Mike Wahler wrote:
....
Most people I know tell me I have
an extraordinary sense of humor.


This proves nothing. BTW, it could stand for "none at all" as well.

Jirka

Nov 13 '05 #121
On Sun, 12 Oct 2003 14:11:46 +0200, in comp.lang.c , Jirka Klaue
<jk****@ee.tu-berlin.de> wrote:
Mike Wahler wrote:
...
Most people I know tell me I have
an extraordinary sense of humor.


This proves nothing. BTW, it could stand for "none at all" as well.


Mind you, typically, people mean "bizarre" or "peculiar" when they say
that... :-)

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/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 #122
> > > > i disagree on that.
>how can you make sure that all data is properly
> encapsulated if
> the language provides no support?

It does provide it. What do you mean by "properly"?

struct data
{
int details;
};

The value 'details' is properly encapsulated inside
the struct type 'data'. This encapsulation could
indeed be corrupted via making coding errors, but
this does *not* mean the encapsulation is 'improper'.


This is no encapsulation. encapsulation means that nobody (except the class
itself)
can access the variable directly, or the direct acess is limited to certain
classes for example derived classes or friend classes.

You are talking about things you don't understand. But the same is true for
me when i talk about plain C :)
The existence of the possibility of coding errors does
not preclude a program from being expressed with OOP.
A language's enforcements of OOP concepts is a very
useful tool, but need not be present for a program
to be expressed using OOP.
This is the point of encapsulation. it simply cannot happen that you access
a variable that you have no access to,
due to coding mistakes (Except you unintentional manipulate the variable
using a memory address if you know its offset in the struct/class)
No. 'for_each()' is simply a function which iterates
through a sequence, and applies a function to each
member of that sequence. It's a generalization of
a simple 'for loop', designed to be useful with
the standard library 'container' abstraction.
Nothing at all to do with 'functional programming'.


Functional programming means you don't say how you want it done like in
[C/C++/Pascal or similar] but you just say what you want have done.

for (int i=0; i<10; i++) a[i]+=2; /* you excatly say how to do it */

for_each (myContainer, MultiplicateWith(2)) /* you just say what is to do
you don't care about how it should be done */

That's the way functional languages like haskell or lisp or whatever solves
problems.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #123
On Fri, 10 Oct 2003 15:12:53 +0200, cody wrote:
"Mike Wahler" <mk******@mkwahler.net> wrote:
Most programmers use their brains, and don't
let the language do all their thinking for them.
then try to programm a fully functioning OOP application in pure C.
it is impossible to make sure no one can unintentional access private
variables.


See, this is a big difference in mindset. I don't often find that I need
to fight with users of my code. So if I do...

struct mystr
{
size_t len; /* public: read-only */
size_t sz; /* private */
char *data; /* private */
};

extern int mystr_allocate(struct mystr *, size_t);
extern int mystr_append_cstr(struct mystr *, const char *);

....it's obvious what you are supposed to do with the struct, and if you
are altering you should be expecting to get burnt.
And, hey maybe somewhere someone needs to look at or alter a member in
some way.

However if you want to fight with your co-workers, then you can do
something like...

/* external header */
struct mystr
{
size_t len; /* public: read-only */
};

extern int mystr_allocate(struct mystr *, size_t);
extern int mystr_append_cstr(struct mystr *, const char *);

/* internal header... */
struct mystr__i
{
struct mystr pub;
size_t sz; /* private */
char *data; /* private */
};

/* C file... */
int mystr_allocate(struct mystr *passed_s1, size_t sz)
{
struct mystr__i *s1 = (struct mystr__i *)passed_s1;
/* ... */
}
storing a function pointer in a struct is commonly used by C programmers.
But i noticed that some programmers abused this to fake OOP features.


And this is fake compared to typing "virtual" ... why?

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

Nov 13 '05 #124
cody wrote:
> > > i disagree on that.
> > >how can you make sure that all data is properly
> > > encapsulated if
> > > the language provides no support?
It does provide it. What do you mean by "properly"?

struct data
{
int details;
};

The value 'details' is properly encapsulated inside
the struct type 'data'. This encapsulation could
indeed be corrupted via making coding errors, but
this does *not* mean the encapsulation is 'improper'.


This is no encapsulation.


It's not a great example of encapsulation, but it can be legitimate,
depending on your definition of "encapsulation".
encapsulation means that nobody (except the
class itself)
can access the variable directly, or the direct acess is limited to
certain classes for example derived classes or friend classes.
That depends on your definition of "encapsulation". You seem to be using the
"Design Patterns" definition, which isn't the one I'd have chosen. You are
basically arguing over definitions, not concepts.
You are talking about things you don't understand. But the same is true
for me when i talk about plain C :)


Then stop talking about C, and start reading about it instead.

--
Richard Heathfield : bi****@eton.powernet.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 #125
On Sun, 12 Oct 2003 15:58:13 +0200, in comp.lang.c , "cody"
<do*********************@gmx.de> wrote:
This is no encapsulation. encapsulation means that nobody (except the class itself)
can access the variable directly, or the direct acess is limited to certain
classes for example derived classes or friend classes.
This is what C++ defines encapsulation as, sure. But encapsulation was
around before C++ you know.Try to define it without using C++isms,
before you spout caeculum tauri.
You are talking about things you don't understand.
ROFL.
No. 'for_each()' is simply a function which iterates
through a sequence, and applies a function to each
member of that sequence. It's a generalization of
a simple 'for loop', designed to be useful with
the standard library 'container' abstraction.
Nothing at all to do with 'functional programming'.

Functional programming means you don't say how you want it done like in
[C/C++/Pascal or similar] but you just say what you want have done.


Indeed. What has this to do with your point?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/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 #126
> >This is no encapsulation. encapsulation means that nobody (except the
class itself)
can access the variable directly, or the direct acess is limited to certain
classes for example derived classes or friend classes.
This is what C++ defines encapsulation as, sure. But encapsulation was
around before C++ you know.Try to define it without using C++isms,
before you spout caeculum tauri.
You are talking about things you don't understand.


ROFL.


Mike said that:
struct data
{
int details;
};


is properly encapsulated data. It isn't.

Maybe he meant that if one would use this struct as opaque datatype, yes
that would indeed be good encapsulation.
If he actually meant that, he was right. I wasn't aware that OOP is so well
understood by C-programmers.
This always was a contradiction for me.
No. 'for_each()' is simply a function which iterates
through a sequence, and applies a function to each
member of that sequence. It's a generalization of
a simple 'for loop', designed to be useful with
the standard library 'container' abstraction.
Nothing at all to do with 'functional programming'.

Functional programming means you don't say how you want it done like in
[C/C++/Pascal or similar] but you just say what you want have done.


Indeed. What has this to do with your point?


for_each() says: Iterate throw all items in this container and you don't
have to say how it should do that.
Isn't that what functional programming is?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #127
[comp.std.c removed from follow-up list]

On Wed, 8 Oct 2003, cody wrote:
pieces of the application where speed really matters you can still use
"normal" functions or even static methods which is basically the same.
Suck it and see.


?


A colloquialism roughly equivalent to "why don't you try it and find
out, instead of whining to me about it?"

int main(void)
{
const int new = 6; /* I rest my case */
return 0;
}


i though in standard C, there isn't such a thing like "const" you can only
use macros to fake them.


Well, you're wrong. Your response here, and your response to ERT,
demonstrate that you apparently have a large gap in your C knowledge
spanning roughly the years 1988-1998. (While "ancient" K&R C didn't
have 'const', it has been standard C since 1989, and C99 didn't
change much in this respect.)

each struct
and enum have to be prefixed with "struct" and "enum".


Poor baby.
Translated from Brit-sarcasm again, for the hard-of-humour:

Poor baby. Whine about it, why don't you? Most people
here are probably inclined to say that specifying 'struct'
and 'enum' is a *good* thing, since it makes it more obvious
what you're doing. In related news, Brussels sprouts are
good for you.

[Okay, that wasn't so much "translated" as "expounded."]

void foo(struct MyStruct struct){}

in C you cannot omit the keyword "struct". when it compiles without "struct"
you probably using a C++ compiler.


False. The above is neither C *nor* C++; it's a syntax error in
both languages. (And you should read up on 'typedef'; it's the C
Gods' answer to the keyword-impaired.)
Yes, there is. C is simple,


agreed.
portable,


agreed.
and very very fast. Those are important qualities.


not faster than C++. why should it?


"Suck it and see," remember? I could run some size and speed
benchmarks on my C and C++ compilers, and let you know the
quantitative differences, but why should I bother? You're the
one who wants to know! You do it!

(Oh, and re your response to Jack Klein: While IMHO Jack was a
bit harsh, and a bit defensive, his criticism of your style was
dead on. You really *don't* seem to know very much about C,
and haven't demonstrated a terrible amount of knowledge of C++
either (not that that would be on-topic here), yet you want us
to prove to you somehow that C is "still relevant," or something.
Why not read a book or two and do your own research? Ask a C
newsgroup, get a C answer.)

-Arthur
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #128
In article <cl****************@plethora.net>,
cody <do*********************@gmx.de> wrote:
[Somebody else, whose name cody snipped, wrote:]
There is both a speed and size penalty for using C++ where
pain C would do. The penalty isn't as bad as it used to be.
There tends to be a speed and size penalty for using C++ features
that C doesn't support. There would also be a speed and size penalty
(probably larger, but not noticeably so, especially not compared to the
programmer time cost) for writing C code to match the C++ features that
C doesn't have.
Note that this is a rather weaker statement than the one quoted above.
there should be no difference between the calls of

class A{ public: static void a(){ } }

and

void a(){}


In fact, there should be no difference between the calls of

class A{ public: void a(){} };

and

void a(struct A *){}

(Or, if you really hate typing "struct" that much:

typedef struct A A;
void a(A *){}

). Of course, making the "this" pointer explicit probably has a
programmer time cost for keeping track of various things - if you want
to write C++ code, you're better off writing it in C++ than in C.

C has constants. We usually use typedefs rather than struct
and enum tags.


is "const float PI=3.14" possible in plain C?


Yes. (Even C90.) It has different semantics than in C++ (and at least
one highly respected comp.lang.c poster[1] considers C's const semantics
broken, and can give good reasons), but if you don't try to confuse
the compiler (or manage to confuse it without trying), something like
"const float Pi=3.14159" will do exactly what you expect.
dave

[1] I'm thinking of Chris Torek, though there are probably others. See
http://groups.google.com/groups?q=co...up:comp.lang.c
for enlightenment on this subject (or drop the "const+broken+",
and perhaps the "+group:comp.lang.c", for more general enlightenment).

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Programmers have a problem. It's a secret we try to keep among ourselves.
We really like this stuff. We do it even when they don't pay us. Don't tell
anybody. --Joe Wright in comp.lang.c
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #129
cody <do*********************@gmx.de> scribbled the following
on comp.lang.c:
> pieces of the application where speed really matters you can still use
> "normal" functions or even static methods which is basically the same.
Suck it and see. ?
It means "try it and see".
int main(void)
{
const int new = 6; /* I rest my case */
return 0;
} i though in standard C, there isn't such a thing like "const" you can only
use macros to fake them.
Well you thought wrong. Have you read a textbook about C?
> each struct
> and enum have to be prefixed with "struct" and "enum".


Poor baby.

void foo(struct MyStruct struct){} in C you cannot omit the keyword "struct". when it compiles without "struct"
you probably using a C++ compiler.
You probably didn't understand the reply. What's so horrible about
having to type "struct" or "enum"? Are you having difficulties typing
such long words?
and [C is] very very fast. Those are important qualities.

not faster than C++. why should it?


Um, languages aren't fast or slow. Implementations of them are.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #130
cody wrote:
i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++.


This is laughable. It is C++ that is best known for faking OO features!
If you're looking for an OO extension to C that is actually well done,
one that is additionally a proper superset of C, you should be looking
at Objective-C. But that's still in the C family. If you don't want C,
don't use C; don't use C++ and pretend you're not using C, though.


so why is objective C used my nobody? except you maybe :)


Mostly because nobody uses it. Many have never even heard of it, fewer
yet have seen it, and fewer than that have ever written code in it.
C/C++ are the industry norms and Objective-C just hasn't had its day in
the sun yet.

Actually there are several issues with Objective-C:

* No standard.
There is absolutely no standard that compilers must adhere to, and
there are several variations of language abilities. For instance, one
language feature on some compilers called a "Category" allows you to
attach methods to a class that already exist, this can be done through a
loadable library. Many compilers don't implement Categories and among
those that do there is dispute as to how they work.

* Poor adoption - unless you use MacOS X.
There is only one OS where Objective-C is use frequently. Everywhere
else it is an anomoly.

* Lack of good libraries to use except on a few systems.
If you use MacOS then of course ObjC is perfect for your use. In
other environments on the other hand you have either wrappers to C
libraries or attempts at making Unix look and act like Next or MacOS
(which is of course unix trying to look like NeXT). The NeXT API is
beutiful, a work of art, but implementations should alter it when it
runs afoul of system norms; no implementation currently does.

Objective-C is a very elegant language and as far as OO languages go it
is the best I have ever used, but I can only compare to C++ and Java.
The learning curve is very small compared to C++ especially if you
already know C; this is a side effect of the language's simplicity.

I used to have a whole list of links for the language at an old site. I
devoted much time to advocating its use. But I rarely use it anymore,
all the more the pity. If there was a nice API, like the NeXT set of
classes, that behaved like a normal Unix library (in that I can write
applications that expect to be on a unix filesystem instead of their own
".app" directory) I would probably do much of my work in that language.
It is *much* easier to use than the alternatives.

NR
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #131
cody wrote:
void foo(struct MyStruct struct){}

in C you cannot omit the keyword "struct". when it compiles without "struct"
you probably using a C++ compiler.

typedef struct
{
int a;
int b;
} foo;

void bar(foo data)
{
}
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #132
cody wrote:
C supports the const keyword now.


since when? C99?


I've been using it in C90 code for at least a decade now. I don't have a
copy of the C90 standard, so I can't be sure, but I suspect it was
introduced in C90.
each struct and enum must be prefixed with "struct" and "enum".


typedef struct X {
// public data members
} X;

in C is the same as

struct X {
// public data members
};

in C++.


and in function declarations? is void foo(X x){} allowed?


Yes, of course. it's a typedef, like any other.

In another message, you asked:
Obviously your knowledge of C is minimal.


what makes you believe that?


Well, being unaware of 'const' and 'typedef struct' doesn't exactly make
you seem like an expert.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #133
"cody" <do*********************@gmx.de> wrote in message news:<cl****************@plethora.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.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #134
"cody" <do*********************@gmx.de> wrote in message news:<cl****************@plethora.net>...
...
int main(void)
{
const int new = 6; /* I rest my case */
return 0;
}
i though in standard C, there isn't such a thing like "const" you can only
use macros to fake them.


In C++, a const-qualified integer variable can be used in places where
an integer constant expression is required; that's not true in C.
However, both languages allow const-qualification.
each struct
and enum have to be prefixed with "struct" and "enum".


Poor baby.


void foo(struct MyStruct struct){}


C isn't as clumsy as you think. The second 'struct' is not only not
necessary, but actually a syntax error.
in C you cannot omit the keyword "struct". when it compiles without "struct"
you probably using a C++ compiler.


Or typedefs.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #135
In article <cl****************@plethora.net>, th*@cs.ucr.edu writes
In comp.std.c cody <NO****************@gmx.net> wrote:

C is pretty much, but not quite, a sublanguage of C++.
C++ is based on C90 However C++ is no longer a super set of C. They are
different languages.
C programmers
who don't use the non-C++ features of C are programming in C++ whether
they claim to or not. They are restricting themselves to an older,
more established, more easily learned, and more easily implemented
subset of C++. But they are writing in C++ --- non-idiomatic C++, but
C++ nevertheless.


This is not true. The are using C. C++ Inherits from C NOT the other
way round.

Chris
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #136
[Followups set to comp.lang.c]

cody wrote:
> pieces of the application where speed really matters you can still use
> "normal" functions or even static methods which is basically the same.
Suck it and see.


?


The only way to /know/ what the performance of your program will be like is
to try it out. Even then, your results will not be generally applicable.
int main(void)
{
const int new = 6; /* I rest my case */
return 0;
}
i though in standard C, there isn't such a thing like "const" you can only
use macros to fake them.


That is an indication that you should spend less time insulting experts and
more time reading what they write, if you wish to be taken seriously in the
C programming community.
void foo(struct MyStruct struct){}

in C you cannot omit the keyword "struct". when it compiles without
"struct" you probably using a C++ compiler.


Your example code will not compile in either language.

Here is an extract from a C header file of my own devising. As you can see,
it uses a type named TCP. As you can't see, the word "struct" is completely
missing, despite the fact that TCP /is/ indeed a name I have chosen for a
struct type.

/*! Transmission Control Protocol connection abstractions */
/*! Connect to a TCP server */
TCP *TCPConnect(const char *server, unsigned short port, FILE *fplog);

/*! Set the logging level */
int TCPSetLogLevel(TCP *connection, unsigned long LogLevel);
/*! Disconnect from the server (invalidates the connection) */
int TCPDisconnect(TCP *connection);
/*! Send a TCP packet */
int TCPSend(TCP *connection, const void *p, size_t len);
/*! Receive a TCP packet */
int TCPReceive(TCP *connection, void *p, size_t len);

Can you say "typedef"?

--
Richard Heathfield : bi****@eton.powernet.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
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #137
>>C supports the const keyword now.
cody wrote:
since when? C99?
No, since the first C standard in 1989.
and in function declarations? is void foo(X x){} allowed?

[where X is a typedef for a structure]

Of course it's allowed.

For somebody who feels free to criticize C,
you sure don't seem to know much about it.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #138
th*@cs.ucr.edu wrote:
Compiling C programs with a C++ compiler has the benefit that C++
compilers are required to perform intermodule type checking. But I'm
told that this intermodule type checking is a curse when one tries to
use precompiled libraries that have been compiled on different C++
compilers, since that checking is usually based on name-mangling and
there is no name-mangling standard. (Perhaps others have more
experience with that issue.)


On essentially any platform there is a unique standard API
for C linkage. And it is easy to get that linkage from C++
by using "extern C". Therefore, libraries written in C are
readily used from both C and C++ applications. Libraries
that rely on C++-specific features (e.g. classes) are not
readily used from C applications.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #139
> void foo(struct MyStruct struct){}

in C you cannot omit the keyword "struct". when it compiles without "struct" you probably using a C++ compiler.


unless:

typedef struct X { int x; } X;

void foo(X x) {}

foo((X){1});
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #140
"cody" <do*********************@gmx.de> wrote in news:clcm-20031008-0005
@plethora.net:

is "const float PI=3.14" possible in plain C?


You just confirmed Jack Klein's assesment of your knowledge of C.

--
A. Sinan Unur
as**@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uc*@ftc.gov
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #141
C is much more alike the final machine code, and that is a benefit
that some programmers take advantage of. This is handy when coding
microprocessors, which are mostly done in C, since assembler quickly
gets out of hand. Also when core are to be translated in to HDL
language to be realized in hardware, most often C (and SystemC) is
used.

A wild guess is that every minute of the day, there is more micro
processor code running than PC code running. (?)

If this benefit is not used, I don't think that there are any big
advantages with C except that it might be easier to learn.

Best regards,
Andreas Lundgren
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #142
On 08 Oct 2003 05:35:19 GMT
"cody" <do*********************@gmx.de> wrote:
i though in standard C, there isn't such a thing like "const" you can
only use macros to fake them.

Maybe you should read the standard.
The const keyword is certainly defined, but it has a different meaning
than in C++.
const int foo = 4;
In C, foo is a variable and will be treated as such.
int *pf = (int *)&foo;
*pf = x;
By using casts, you can defeat the const.

In C++, foo would be treated as a true compile-time constant, and would
not actually be placed in memory.
--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #143
On 08 Oct 2003 05:35:25 GMT
"cody" <do*********************@gmx.de> wrote:
There is both a speed and size penalty for using C++ where
pain C would do. The penalty isn't as bad as it used to be.


there should be no difference between the calls of

class A{ public: static void a(){ } }

and

void a(){}
C has constants. We usually use typedefs rather than struct
and enum tags.


is "const float PI=3.14" possible in plain C?

Define "plain C". This is possible in standard C, but not in K&R C.
--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #144
In article <cl****************@plethora.net>, cody
<do*********************@gmx.de> writes
> each struct
> and enum have to be prefixed with "struct" and "enum".


Poor baby.


void foo(struct MyStruct struct){}

in C you cannot omit the keyword "struct". when it compiles without "struct"
you probably using a C++ compiler.


Of course you can, but in C you have to explicitly create a typename
with typedef.

--
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.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #145
cody wrote:
[...]
for_each() says: Iterate throw all items in this container and you don't
have to say how it should do that.
Isn't that what functional programming is?


Good grief man, a few posts ago you were talking like you were the King
of Functional Programming, and now this. Please stop the pretence, you
may get away with that with your real-life friends - but not here.

Several people have suggested that you learn a bit about the topics you
write about before stating an opinion. It's hard work (reading books,
doing actual coding, getting to grips with basic concepts and
algorithms, exploring languages and paradigms along the way) and can
take years of dedicated work. It can be worth it though - computer
science is a fascinating subject with many, many faces.

I've been at computers for 18 years now, have an MSc in applied computer
science, and still I don't know half that some of the regulars here know
(and that's a loose upper bound). I'm glad I can actually read their
posts and understand most of it, and can formulate questions precisely
enough to get some very valuable feedback.

Now I am not suggesting you take a hike and rejoin in 2021, but a little
bit of humbleness in the face of people who are, by any standard, much
more qualified than you are to discuss computer language issues wouldn't
hurt.

At least you got your keyboard fixed, that's something :-)

Regards,

Sidney Cadot

Nov 13 '05 #146
In article <cl****************@plethora.net>, <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.
Compiling C programs with a C++ compiler has the benefit that C++
compilers are required to perform intermodule type checking. But I'm
told that this intermodule type checking is a curse when one tries to
use precompiled libraries that have been compiled on different C++
compilers, since that checking is usually based on name-mangling and
there is no name-mangling standard. (Perhaps others have more
experience with that issue.)


It also breaks certain very useful idioms of standard C, such as automatic
(void *) conversions.

Anyway, there is a great deal more to a language than "this compiler will
accept it". Your argument works just as well for Objective C; so far as
I can tell, any valid C program is a valid Objective C program. It works
even better for "C With Classes", even though that's a dead language, than
it does for C++.

In reality, to say you are "programming 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.

Stylistically, I use C instead of C++ because I am better able to express
what I mean in C, and in particular, because I have then some small hope of
being able to read the code later. If you exclude all of the features of
C++ which have tended to produce awful and unreadable code, you might as
well just write in plain old C, and avoid the "enhancements" all together.
If I want an OO bag on the side of C, I prefer Objective C; it makes the
magic features explicit, rather than implicit. If I want an OO language with
C-like syntax, I'll use Java. So far, I've found no tasks for which C++
seemed to be a good fit, except for maintaining existing code that was written
in C++.

-s
--
Copyright 2003, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 13 '05 #147
> > void foo(struct MyStruct struct){}

C isn't as clumsy as you think. The second 'struct' is not only not
necessary, but actually a syntax error.

sorry my mistake. should read void foo(struct MyStruct myStruct){}

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #148
"Sidney Cadot" <si****@jigsaw.nl> schrieb im Newsbeitrag
news:bm**********@news.tudelft.nl...
cody wrote:
> [...]
for_each() says: Iterate throw all items in this container and you don't
have to say how it should do that.
Isn't that what functional programming is?

The last sentence was not actually meant as a Question.
Good grief man, a few posts ago you were talking like you were the King
of Functional Programming, and now this.
I've never claimed that!
At least you got your keyboard fixed, that's something :-)

:)

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #149
cody wrote:
for_each() says: Iterate throw all items in this container and you don't
have to say how it should do that.
Isn't that what functional programming is?
The last sentence was not actually meant as a Question.
Well, in that case I wonder what it was meant like. I hope you're not
implying it was a rhetorical question, actually meaning "That is what
functional programming is" ... Because you would be sadly mistaken.
Good grief man, a few posts ago you were talking like you were the King
of Functional Programming, and now this.

I've never claimed that!


I never said you claimed that. I said you were talking like that,
posturing. So far you've given no indication whatsoever that you have
any real understanding of either C, C++, or functional programming.
You're just touting a few isolated half-facts and ill-conceived
misguided ideas, I have yet to see anything remotely resembling insight
in any of your posts. Don't you realize from the many similar reactions
that many here are getting fed-up with this attitude?

Now if that is your goal - congratulations. We Have Been Trolled, you
can move on now. If you actually want to improve your knowledge of C, I
sincerely suggest a change of attitude. So what's it gonna be?

Sidney

Nov 13 '05 #150

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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)...
2
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...
3
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...
0
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. ...
1
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...
4
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...
1
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 ...
2
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...
3
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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 ...

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.