Making C better (by borrowing from C++)

C

Chris Hills

Malcolm McLean said:
If a product is open source then in theory you can reengineer it.

This is true of virtually any other commercial software. I can supply
source but it is no Open source.
You can keep your changes secret if they are for personal / in house
use, but, for obvious reasons, you may not sell the enhanced version.

Unlike other software where you can.
In practise most people are not very interested.

This is true they like the idea of being able to do things but in
practice rarely do.
I am not suggesting that Jacob go open source, by the way. It is huge
problem finding the right business model for software, and open source
with paid support isn't viable for everyone

True... It works for companies like Red Hat because they don't have to
finance the initial development of the software.
You seem to have to fiddle with the thing for hours just to get a
little window up on screen. Which?

The it declares all your code deprecated.

Oh I see you mean MS...

Now if most of the desktop uses MS or GCC and the embedded community
uses non-standard compilers anyway who is actually going to use ISO-C?

I think there was a a unifying moment in the early 1990's and then the
ISO panels screwed it. Next year ( in a couple of days) we will be a
decade on from the last C standard and still virtually no one is really
using it.
 
C

Chris Hills

Richard Heathfield said:
Chris Hills said:



Because I promised my wife I wouldn't touch the damn thing on Christmas
Day. :)

:)
I make it a point of having the computers off for at least 36 hours at
Christmas.
 
R

Richard Heathfield

Chris Hills said:

GCC is proprietary It has a license just like MS, Borland and others.

"Proprietary" means "of the nature of property; legally made only by a
person or body of persons having special rights, esp a patent or
trademark; pertaining to or belonging to the legal owner; (of a company,
etc) privately owned and run". Who do you think "owns" gcc?
 
R

Richard Heathfield

jacob navia said:
I must have been dreaming when you posted a discussion about the errata
in your book???

No, you weren't dreaming. It is also true that someone who read that
discussion was somewhat motivated to go out and buy the book.

Nevertheless, no sane person is going to believe that the publication of a
bug list constitutes promotion (especially when the book is out of print).

Of course, there is nothing stopping you from trying to persuade insane
people of your viewpoint.
 
P

Paul Hsieh

My experience does not match your assertion.

Clearly not. I commonly have to read code, and I find it takes
several
times as long to read C++ code precisely because its so hard to track
down where a variable has been declared. Ordinarily, I would expect
that
if its not declared at the top of some enclosing scope then it is
either
a global or an attribute of "this" object. Except its not -- because
I
have to check every for(...) and in fact, every line of code (except
disjoint scopes) up until the start of the function.

The main advantage of C89 is that it really is just the top of each
enclosing scope and it can only be a local, a file scope static or an
extern global. Its typically extremely fast to scan for the first
two,
leaving the last check (looking through .h files) unnecessary. But
usually the difference between a file static/global and an extern
global
is not relevant to any given function -- you just want to know if a
variable is local. In C89, you know that with a quick scan by eye
with
a page-up keystroke or so.

With C99 we are now forced to scan every line of code up to the start
of each function.

Some will chime in and claim that you should be using some search
function in your editor or some source code browser. But that's
nonsense
as you typically can only do *one* of those at a time. I.e., you
might
be doing a "find next" on some important thing you are searching for
that
you want to retain the state for, and while you are doing so you want
to
check where a potential local is being declared without clearing your
search buffer. Furthermore, some editors (such as the Visual C++ text
editor) don't have a backwards search. This is not some fanciful
scenario
I am artificially constructing -- I *DO* this nearly every day.
Only if you know which scope it is defined in.

And just how deeply scoped do you write your code? There is an
explicit
syntactical pointer; namely the "{" character. Most people also
indent
their code to make finding these "{" characters visually obvious.
[...] Since scopes nest in C,
there's no way to be certain unless declarations are restricted not
merely to the top of the scope, but to the top of the function.

This is the very definition of pedantry. The problem of finding the
top
of a function is not significantly different from finding the set of
scope
beginnings up to the top of the function declaration. The depth of
your
scopes is typically O(log(lines in function)).
[...] I would
argue against the "top of the function" solution, but since you don't
seem to be advocating it, I won't bother.

Since a large fraction of the code I've ever worked on was written by
other people, there's no guarantee that any given variable is declared
in any particular scope, no matter what I might prefer. I have to do
the same kind of backwards search to find the top of the right scope
that I would have to perform to find a declaration that's not at the top
of a scope, so I don't see how it saves me any trouble.

Search backwards through indents or "{"s is the same as scanning line
by
line to you?
They also make the program harder to read and comprehend, in my experience.

Odd. I find myself swinging in the other direction. Very often a
function
does things in distinct steps, where is it a valuable hint to separate
these
by scopes -- that typically corresponds exactly to where you want
separate
scopes to divide your local variables.
In my experience, the search is easier whether I use my eyes or other
tools to perform it.



In my experience, code is clearer when definitions are closer to first
use, than it is when they're artificially constrained to be declared
somewhere prior to first use.

Well we clearly just have radically different experience.

The main problem with your approach is that the closest first use
might
be *wrong* since the local variable can be used early *and* late in a
function, in which case its got to be put into a high enough position
in an enclosing scope anyways:

type function (...) {
/* A */ ...
if () {
... /* Don't touch x */
}
... /* B */ ...
switch () {
... /* Don't touch x */
}
... /* C */ ...
for (/* D */ ...) {
/* E */
...
touch (&x); /* <-- Looking here */
...
}
...
return x; /* <-- Or looking here */
}

So if you happen to be scanning either either of the places which are
marked "looking here" you need to check A, B, C, D (and possibly E)
for
the declaration of x. In C89 you only need to check A (and possibly
E).
In fact you also need to check more lines at A (and possibly E) with
C99/C++.

This isn't just some worst case -- if x is a static or global (or
object attribute) you will commonly see code like this and have to
scan
all those positions before you realize it is such.
 
P

Paul Hsieh

Paul Hsiehwrote:


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.

I know the difference; you should read my entire post. My point
was to vacate his false claim that it would improve compiler
optimization. It does not.
 
J

jameskuyper

Paul said:
Clearly not. I commonly have to read code, and I find it takes
several
times as long to read C++ code precisely because its so hard to track
down where a variable has been declared. Ordinarily, I would expect
that
if its not declared at the top of some enclosing scope then it is
either
a global or an attribute of "this" object. Except its not -- because
I
have to check every for(...) and in fact, every line of code (except
disjoint scopes) up until the start of the function.

The main advantage of C89 is that it really is just the top of each
enclosing scope and it can only be a local, a file scope static or an
extern global. Its typically extremely fast to scan for the first
two,
leaving the last check (looking through .h files) unnecessary. But
usually the difference between a file static/global and an extern
global
is not relevant to any given function -- you just want to know if a
variable is local. In C89, you know that with a quick scan by eye
with
a page-up keystroke or so.

With C99 we are now forced to scan every line of code up to the start
of each function.

Some will chime in and claim that you should be using some search
function in your editor or some source code browser. But that's
nonsense
as you typically can only do *one* of those at a time. I.e., you
might
be doing a "find next" on some important thing you are searching for
that
you want to retain the state for, and while you are doing so you want
to
check where a potential local is being declared without clearing your
search buffer. Furthermore, some editors (such as the Visual C++ text
editor) don't have a backwards search. This is not some fanciful
scenario
I am artificially constructing -- I *DO* this nearly every day.


And just how deeply scoped do you write your code? There is an
explicit
syntactical pointer; namely the "{" character. Most people also
indent
their code to make finding these "{" characters visually obvious.

I personally indent consistently by 4 spaces, and make a point of
splitting the function if the required indentation is more than 1/2
the page width (40 characters => 10 levels). I also try to avoid
having any function who's body extends over more than one full printed
page (80 characters wide, 66 lines long); that limit tends to
indirectly constrain my indentation much more strongly than the direct
limit I've specified above.

However, the key point is that I maintain a lot of code that was not
written according to these guidelines. I've got a fair amount of code
where a single function might contain hundreds and even thousands of
lines. If I had the resources to do so, I might consider re-writing
those changes. However, in the absence of any known actual bugs in the
code, it's pretty hard to justify applying my scarce resources to
perform aesthetically motivated fix-ups.
[...] Since scopes nest in C,
there's no way to be certain unless declarations are restricted not
merely to the top of the scope, but to the top of the function.

This is the very definition of pedantry. The problem of finding the
top
of a function is not significantly different from finding the set of
scope
beginnings up to the top of the function declaration. The depth of
your
scopes is typically O(log(lines in function)).

Nor it it very different from searching for previous definitions of
the identifier by name, which I've found to be a much quicker and more
reliable method.
[...] I would
argue against the "top of the function" solution, but since you don't
seem to be advocating it, I won't bother.

Since a large fraction of the code I've ever worked on was written by
other people, there's no guarantee that any given variable is declared
in any particular scope, no matter what I might prefer. I have to do
the same kind of backwards search to find the top of the right scope
that I would have to perform to find a declaration that's not at the top
of a scope, so I don't see how it saves me any trouble.

Search backwards through indents or "{"s is the same as scanning line
by
line to you?

Finding the indents or "{"s isn't sufficient; then you must still scan
line by line for the matching declaration; the context switch between
the two search modes costs at least as much as the nominally more
efficient mode saves; that's true whether using my eyes or using a
text editor.

....
The main problem with your approach is that the closest first use
might
be *wrong* since the local variable can be used early *and* late in a
function, in which case its got to be put into a high enough position
in an enclosing scope anyways:

type function (...) {
/* A */ ...
if () {
... /* Don't touch x */
}
... /* B */ ...
switch () {
... /* Don't touch x */
}
... /* C */ ...
for (/* D */ ...) {
/* E */
...
touch (&x); /* <-- Looking here */
...
}
...
return x; /* <-- Or looking here */
}

That's not a problem with my approach. My approach has never been
"smallest scope, regardless of whether or not it works". I've always
considered that it was implicitly clear that I was referring to the
smallest scope that is consistent with the actual use of the variable.
 
J

jacob navia

Richard said:
jacob navia said:


No, you weren't dreaming. It is also true that someone who read that
discussion was somewhat motivated to go out and buy the book.

Nevertheless, no sane person is going to believe that the publication of a
bug list constitutes promotion (especially when the book is out of print).

OK OK. Agreed.

And giving away my software is not *really* a commercial activity.

Very indirectly it *can* be construed to that but it isn't. I am
financing this free service to C programmers since ten years,
and sales have never covered the expenses. To present me as a
"shrewd commercial guy" is just not true.
 
K

Kenny McCormack

Richard Heathfield said:
Nevertheless, no sane person is going to believe that the publication of a
bug list constitutes promotion (especially when the book is out of print).

Of course, there is nothing stopping you from trying to persuade insane
people of your viewpoint.

It is a good thing that we know that RH never attacks JN. Otherwise,
we'd be forced to draw a different conclusion from the above.

And note that the above is an insult by any standards. When you start
doing things by the hypersensitive-CLC standards (as witnessed in the
recent "Taleban" (sic) thread), things become even more broken.
 
K

Kenny McCormack

jacob navia said:
OK OK. Agreed.

And giving away my software is not *really* a commercial activity.

Very indirectly it *can* be construed to that but it isn't. I am
financing this free service to C programmers since ten years,
and sales have never covered the expenses. To present me as a
"shrewd commercial guy" is just not true.

Jacob, Jacob. The "commercial" stuff is just a red herring here.
The fact is, they just don't like you. And they never will.
Note that some of them have even gone as far as to call you a "frog" in
print (generally, via sock puppet, to maintain denyability)...
 
C

CBFalconer

Richard said:
Chris Hills said:
.... snip ...

He's also ignoring the fact that the real guru here is Chris Torek,
who knows several hundred times as much about C as I will ever know.


Since I've never, ever promoted the book here, the claim is without
merit.

There are several items I wrote some time ago, some as far back as
the '50s. Like "Richards' book" they are out of print. I see no
great point in urging you all look them up and generate a monstrous
groundswell of demand for them. If you did, I doubt that I would
profit. I suspect this applies equally to Richard.
 
R

Richard Heathfield

jacob navia said:
I am
financing this free service to C programmers since ten years,
and sales have never covered the expenses. To present me as a
"shrewd commercial guy" is just not true.

Well, I can certainly accept that, at least as a possibility. But quite
seriously, you would do better to let other people recommend lcc-win32 for
you, rather than do it yourself.

Even if you believe 100% wholeheartedly that lcc-win32 is the right
solution for a particular problem (and, in fact, even if you're *right* to
believe that, as you may be, from time to time), the very fact that it is
you, the vendor, who recommends it is enough to make people question your
motives.

If, however, your product is recommended here not by you but by those who
have earned the respect of this group by virtue of having provided a great
deal of high quality C help over the years, such a recommendation would be
much more powerful. (Such recommendations may take some time to earn,
however, given the amount of hard work you've put into trashing your
reputation here over the years.)

No matter how honest you think you are, there are always going to be people
who suspect your motives. That's why it's best not to give such people any
ammunition at all.
 
K

Keith Thompson

Richard Heathfield said:
Chris Hills said:



"Proprietary" means "of the nature of property; legally made only by a
person or body of persons having special rights, esp a patent or
trademark; pertaining to or belonging to the legal owner; (of a company,
etc) privately owned and run". Who do you think "owns" gcc?

The Free Software Foundation holds the copyright (try "gcc --version").

But surely this is off-topic. See misc.int-property and
gnu.misc.discuss for further flame-wars.
 
U

user923005

My experience does not match your assertion.


Only if you know which scope it is defined in. Since scopes nest in C,
there's no way to be certain unless declarations are restricted not
merely to the top of the scope, but to the top of the function. I would
argue against the "top of the function" solution, but since you don't
seem to be advocating it, I won't bother.

Since a large fraction of the code I've ever worked on was written by
other people, there's no guarantee that any given variable is declared
in any particular scope, no matter what I might prefer.  I have to do
the same kind of backwards search to find the top of the right scope
that I would have to perform to find a declaration that's not at the top
of a scope, so I don't see how it saves me any trouble.


They also make the program harder to read and comprehend, in my experience..

I have found that in some cases using {} to create a new block is very
annoying.
I have found that in some cases using {} to create a new block is
wonderful.
Like every other controversial construct (e.g. goto, continue, break)
it can be good or bad, depending on the exact situation.

A microscopic side benefit is that it can reduce peak automatic
storage need.
Of course, it would be a terrible mistake to program using them for
that reason alone.

IMO-YMMV.
 
C

CBFalconer

Chris said:
.... snip ...


Maybe... Compiler vendors produce things they can sell.... or
rather things people want. GCC is hardly "ISO-C" and most
embedded compilers are non-standard.

Nonsense. "gcc -W -Wall -ansi -pedantic" is a quite accurate ISO-C
compiler for C90, and replacing -ansi with -std=C99 makes for a
fairly accurate C99 compiler. This is usually discovered by users
by simply reading the accompanying documentation. I submit that
those incapable of this degree of investigation should not be
composing C source.
 
U

user923005

Your version of "advance" is hardly shared by everyone.  Your
solipsistic attitude has, from the evidence of your recent posts, become
pure egotism.  Ger over yourself, already.  This is not
comp.navia.masturbation, but comp.lang.c.  Almost all your recent posts
have been solely about Jacob Navia, how wonderful he is, and how the
nasty world mistreats him.  Almost none have had more than a passing
reference to C.


And that, silly boy, is either a flat lie or shows that you are
completely out of touch with the world.

I think it is simply a straw man.
 
C

CBFalconer

Richard said:
Chris Hills said:



Because I promised my wife I wouldn't touch the damn thing on
Christmas Day. :)

Boy, have you ever piled up a set of points for the next year!
 
U

user923005

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

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.....)[/QUOTE]

The book is out of print.
 
C

CBFalconer

jacob said:
Malcolm McLean wrote:
.... snip ...


No. If you want to use gcc source code you have to put YOUR
application under the GPL. And if you do not want to put YOUR
application under the GPL you have to pay BIG bucks to Red Hat.

Wrong. You can use gcc freely to develop anything at all. What
you can't do is incorporate GNU source code in your devopment
without licensing that development under GPL.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top