Making C better (by borrowing from C++)

R

Richard Heathfield

(e-mail address removed) said:
I have my chance for what exactly?

Making known your views on whether the topicality of this group should be
extended. Of course, you always have that chance, but in that thread lay
the (or rather, an) opportunity for lots of people to have that discussion
at the same time.
When did I have it?

Now, if you like. I'm sure you can find the thread on Google. It hasn't
been "closed" - Usenet has no such feature.
Was I notified about it?

No less so than anyone else - that is, the discussion was started on
comp.lang.c, so obviously those most likely to see it were those who read
comp.lang.c most.
Should I have read two hundred posts
in the thread I had no interest in after reading first ten
posts?

That's up to you.

Next, what result? Could you show me the result? How many
people have voted? What was on the ballot? You've got no
idea, don't you?

Ian Collins was in fact one of those who took part in that discussion. The
result was posted here:
http://groups.google.com/group/comp.lang.c/browse_thread/thread/32c4358dc0307344#faa1895ecbce478b

(Obviously, that summary can, at best, only be as accurate as the articles
that were posted before the summary was made.)

The start of the discussion was here:

http://groups.google.com/group/comp.lang.c/browse_thread/thread/306800faf6c30d43#a642808d3bf37773
You simply know that "there was a vote"
(did you learn about it from Marc's post? I learned about
it from Marc's post,

You're talking nonsense. Ian was involved in the discussion.
By the way, now I don't know if there really was a vote,

Nobody said "all those in favour, <countcountcount> now all those against
<countcountcount>". Rather, there was a discussion, and people expressed
their opinions, and I made an attempt to document those opinions in a
table.
because I thought there were, but Keith says there wasn't.

It depends on what you mean by "vote". Opinions were expressed, and I then
counted them as accurately as I could manage. And in case you're
interested, I ended up in the liberal minority.
I tried to check, and failed. But I learned another thing:
that mentioning that thread is actually cheating. It's so
huge that it's useless for getting any information about
what people in comp.lang.c think.

That's precisely why I posted a summary article, starting a new thread in
which to do it. The URL can be found above.
 
J

jacob navia

Keith said:
I don't agree with jacob's point, though. Just adding operator
overloading isn't enough to accomodate arbitrary new numeric types.
For example, you need literals (lcc-win uses a 'q' suffix for qfloat).

This problem exists in C++ also and there no solution has been found.

I use a solution (that isn't published as a solution in my proposal)
of loading a dll and executing a function from it.
You also need to define rules for implicit conversions to and from
other numeric types. There are probably other complications I haven't
thought of.

The operator cast will do that.

output_type operator ()(input_type);

will transform input_type into output_type.
I wouldn't mind seeing a mechanism for adding new numeric types
without having to make changes to the language, but I don't believe
operator overloading alone will do the job.

It does. I have implemented the complex numbers with it, and
the qfloat extension.
 
R

Richard Heathfield

Keith Thompson said:

In any case, Chuck is of course correct that operator overloading is
not part of C

If he means user-defined operator overloading (which he has not made
clear), he is correct. But operators are overloaded routinely within C.
Even the humble + operator has many meanings; not only does it have a
variable number of operands, but the types of those operands are by no
means fixed, so we have "+ that adds two int types; + that adds an int to
a double; + that adds two doubles; + that adds a pointer and an int", and
so on. And don't get me started on * ! :)
 
M

Malcolm McLean

Ben Bacarisse said:
Do you have a plan to implement C99? A full C99 implementation would
be more useful to many than extensions that lock programmers in to
your compiler.
The best situation is a good standard that is accepted. We can have a
sensible argument about whether it is better to have an inadequate standard
that is accepted or no accepted standard at all. The worst situation is an
inadequate standard which is largely rejected, but kept alive by a few
implementations.
 
M

Malcolm McLean

Ian Collins said:
Only a psychic compiler can determine the programmer's intent and they
are rare indeed.
A compiler can pretty easily determine wheter a variable is written to or
not, excluding perhaps extremely silly games with saving pointers to disk
and the like.
It cannot determine whether that variable "ought" to be written to or not.
What you are saying with const is that the programmer who writes the word
"const" does know, whilst the programmer who writes *ptr = x does not. Which
will be true at least some of the time, but not always.
 
M

Malcolm McLean

Richard Heathfield said:
Incidentally, I was in the minority (as I suspected I would be). If I can
abide by the majority decision despite not being totally happy with it, I
see no reason why others can't.
I've got very strong views on car use.
However I may not set up my own referendum, and on the basis of that start
organising "car smashes", going into supermarket car parks and burning all
the cars, because my referees have decided that the supermarket business
model is an exercise in almost criminal futility.
(Of course if the supermarkets themselves claim to be above the law it would
be a different story. :) )

Gordon Brown, however, can call a referendum, because he is man in charge of
the government. If it came out against supermarkets with car parks, the case
for closing them down would be overwhelming.

The point is you have to have legitimate authority to make laws.
 
K

Keith Thompson

jacob navia said:
This problem exists in C++ also and there no solution has been found.

I use a solution (that isn't published as a solution in my proposal)
of loading a dll and executing a function from it.

Huh? How does that address the issue of numeric literals?
The operator cast will do that.

output_type operator ()(input_type);

will transform input_type into output_type.

A cast is an explicit operator. I was talking about implicit
conversions. For example, if ``i'' is of type int and ``d'' is of
type double, then in the expression (i + d) the value of i is
implicitly converted from int to double before the addition.
Determining how to specify that kind of thing for new numeric types
without extending the language itself is non-trivial.
It does. I have implemented the complex numbers with it, and
the qfloat extension.

You had to make changes to the language both for complex (_Complex is
a keyword that has to be recognized by the compiler) and for qfloat
(the compiler has to recognize ``1.2Q'' as a qfloat literal).
 
J

jacob navia

Keith said:
Huh? How does that address the issue of numeric literals?

When I see a literal ending with q or Q I call a function from a dll.
like
#pragma numeric('q',qfloat.dll,AsciiToQfloat)
#pragma numeric('Q',qfloat.dll,AsciiToQfloat)
A cast is an explicit operator. I was talking about implicit
conversions. For example, if ``i'' is of type int and ``d'' is of
type double, then in the expression (i + d) the value of i is
implicitly converted from int to double before the addition.
Determining how to specify that kind of thing for new numeric types
without extending the language itself is non-trivial.

You define an operator plus that takes the left hand side
of type1 and the right hand side of type2. Easy.
You had to make changes to the language both for complex (_Complex is
a keyword that has to be recognized by the compiler)

Yes, but that is unnecessary if we use operator overloading
since you just include the corresponding header file
and for qfloat
(the compiler has to recognize ``1.2Q'' as a qfloat literal).

That could be done with the pragma above
 
E

Eric Sosman

jacob said:
What bothers you is that lcc-win tries (and implements) an
effort to make C advance, by incorporating many things that
are necessary in a modern software development environment.

What bothers me is the assumption that it is an "advance"
to adopt every fad-of-the-moment that comes along.
 
E

Eric Sosman

Paul said:
A compiler can always determine if a variable has const semantics
without programmer assistance.

The difference in declaration is about actuality versus
intent. Yes, the compiler can detect when a variable is
initialized and never assigned, or not initialized but assigned
only once, and can in that sense determine that it "has const
semantics." But if the programmer assigns to the variable a
second time, the compiler will determine that it is not const
even if that was the programmer's intent.

For example, imagine an intricate calculation of the X
co-ordinate of something or other, followed by a calculation
for Y that is in all respects identical except for the names
of the variables. The programmer might copy and paste the X
code and then use an editor to change the names of the X-related
variables to their Y-related counterparts -- and might miss
one of them, resulting in a second assignment to one of the
X suite. An explicit const would cause the compiler to squawk
and would alert the programmer to his error; relying on a
purely implicit mechanism might let the error go undetected.

More prosaically, imagine a programmer having a momentary
lapse and mixing up the order of the arguments to memcpy(). For
example, in another recent thread there was code for a sort of
memcpy() work-alike but with the source and destination pointers
interchanged; a programmer going back through the existing code
base replacing the home-brew function with memcpy() calls might
well botch the argument reversal a few times. With explicit
const, some of these could be caught by the compiler:

static const unsigned char escape[] = {
'\033', '[', ESCAPE_CODE_1, ESCAPE_CODE_2, ';' };
char buffer[BUFFERSIZE];
memcpy (escape, buffer, sizeof escape); /* bzzt! */

.... whereas without the `const' the compiler might have no
reason to complain.

General principle: The more we can inform the compiler about
our actual intent, the more it can do to help us when we make
misteaks.
 
K

Kenny McCormack

I've got very strong views on car use.
However I may not set up my own referendum, and on the basis of that start
organising "car smashes", going into supermarket car parks and burning all
the cars, because my referees have decided that the supermarket business
model is an exercise in almost criminal futility.
(Of course if the supermarkets themselves claim to be above the law it would
be a different story. :) )

Gordon Brown, however, can call a referendum, because he is man in charge of
the government. If it came out against supermarkets with car parks, the case
for closing them down would be overwhelming.

The point is you have to have legitimate authority to make laws.

Good points; good post; good use of analogy.

What it boils down to is: What form of government is in force on Usenet
news groups? For most of time, and for most groups, the answer has
always been something which could be described as "True Democracy" (TD) -
aka, Athenian Democracy. That is, everybody votes on every issue (and
everybody's vote counts). An attribute of TD is that no one really has
any power (everybody has equal power).

Now, the point of course, is that no real world country has such a
system today, nor do many corporations. Everything (with probably
countable exceptions) is some form of "Representative Democracy".
"Representative Democracy" (RD) boils down to: individuals have no power;
rather, we employ people who have and wield power.

Now, notice that above I said "most of time and for most groups". My
own view is that there are two significant points to be made about this
generalization:
1) As the Internet and Usenet have evolved and the "chasm" has
been crossed (that's MBA-speak for "The masses have arrived"),
the need for more active policing (an attribute of RD) has
arisen. The masses want and need policing. Now, in fact,
this still hasn't happened on most groups, primarily because
the people involved just want no part of it. So, as
result, Usenet has kind of "withered away". The popular
media pretty much ignores it, and when they do mention it,
they do their best to make it sound obscure and geeky (which
it is - and we like it that way!).
2) CLC (this newsgroup) has, on the other hand, unique in my
Usenet experience, developed a rigid, authoritarian culture.
One that is a form of RD. That is, there are people who run
this place, and we all know and understand that.

Note: Yes, I know the people who run this place will write in to
disagree with #2 above (if they haven't already killfiled me, of
course). Pre-emptive strike (by me): They are lying sacks of crap.

Note also that the people who run this place have a lot in common with
the current GWB admin. More about that in another post...
 
J

jacob navia

Eric said:
What bothers me is the assumption that it is an "advance"
to adopt every fad-of-the-moment that comes along.

Operator overloading is a technique that is well established and by all
means
not the latest fad.

You have no arguments Eric. Why would operator overloading
be a "fad"?

It is not the latest fad in C++ since many people are against it.
In fortran it was introduced YEARS ago.

I have repeated again and again the need to be able to create new types
of numbers
in C.

How would you solve that problem?

There are two technical reports in the commitee discussion about
o decimal floating point numbers for exact operations
o fixed point representations.

Both are needed. How would you incorporate those into the language?

Don' you see that we can't change the language (and force all
implementations to support) all possible types of numbers?

Please explain how would YOU do this.

Thanks
 
C

Chris Hills

Richard Heathfield said:
(e-mail address removed) said:



Are you saying that you would prefer the group to lower the quality of its
advice?

Lower quality no... Better quality yes.
Being pedantically correct may be the wrong answer.

Ie the usuall "there is no **** in C" from CBF when some one says
something that is not in ISO, K&R, ANSI-C or any N document but is used
by a very large number of C programmers.

Usually things that are not pertinent to the question concerned.

Incidentally most of the work I am involved in is high integrity or high
reliability. Portability is not a major concern. In fact I subject that
portability is a minority concern.
 
C

Chris Hills

Richard Heathfield said:
(e-mail address removed) said:


That is what Chris Hills was suggesting - a relaxation of pedantry (which
is simply another way of saying "be less accurate in future").

I did NOT say that. The pedantly I was refering to was all the OT crap
we get. Things like CJF going through EVERY like of some ones posted
source commenting which items are not standard C (though he does not say
if he is referring to K&R1, K&R2, C89, C90, C95, C99 or some N document)
and then not answering the question asked.

THAT is the sort of pedantry I meant.
If you don't want that either, then you and I are on the same side - the
side of "getting it right", no matter how unpopular that can sometimes be.

But getting it "right" at the expense of giving a *helpful* answer is no
help at all.
If commercial exploitation of comp.lang.c is not opposed,

Jacobs compilers are as free as GCC compilers. (And the MS & Borland
ones)
it will prevail,
and learners of C will be the losers. Yes, opposing commercial
exploitation of the group can be tedious. Yes, it's repetitive. Yes, it
can be misinterpreted as a vendetta. Nevertheless, I still think it's
worth doing.

I don't
 
C

Chris Hills

[QUOTE="jacob navia said:
So this is your new thing: JN is a spammer. And you are fighting
"commercial exploitation of comp.lang.c". Yeah.
JN vs RH is going on here for years, and suddenly it becomes
fighting spam which can be *mis*interpreted. Good one!
Yevgen

That is ridiculous. I could also argue that RH exploits this group
commercially since the fact of him being the guru here promotes his book
and he earns money with it.[/QUOTE]


Bloody good point! I had not thought of it that way. However as Jacob's
compiler can be obtained for Free and Richards book can not Richard is
more commercial than Jacob :)

(get out of that one.....)
 
C

Chris Hills

Let me put it this way: What is standard C?

According to the "language Taliban"

K&R1
K&R2
C89
C90
C95
C99


any non-issued N document they can find.

But NOT any widely used implementation of C not matter if it is used
more widely than any of the aforementioned "standards" above.
 
C

Chris Hills

Ian Collins said:
You had your chance, now you have to put up with the result. That's the
way democracy tends to work.

The problem is that the vast majority who would have voted have long
since been chased off by the Language Taliban
 
C

Charlton Wilbur

MMcL> I've got very strong views on car use. However I may not
MMcL> set up my own referendum, [...]

MMcL> Gordon Brown, however, can call a referendum, because he is
MMcL> man in charge of the government. If it came out against
MMcL> supermarkets with car parks, the case for closing them down
MMcL> would be overwhelming.

MMcL> The point is you have to have legitimate authority to make
MMcL> laws.

Governments derive their powers from the consent of the governed. We
had a discussion about this, and found that the majority of the people
who cared enough to state an opinion preferred limiting the discussion
here to portable standard C, as defined by C99, C89, or K&R.

What is so hard to understand about that?

Charlton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top