K
Keith Thompson
Rod Pemberton said:BTW, I've heard one of the Pascal standards added pointers...
<OT>Pascal has always had pointers.</OT>
Rod Pemberton said:BTW, I've heard one of the Pascal standards added pointers...
Ed Prochak said:not if you can live with a WARNING message.
I thought those died out. Were any those CPU's actually used in a computer
sufficiently advanced enough to compile C?
But other HLL's don't even have register storage.
I know that it is just a suggestion. The point is Why was it included
in the language at all? Initially it gave the programmer more control.
Prochak said:[C] doesn't impose strict data type checking, especially between
integers and pointers.
not if you can live with a WARNING message.
Keith said:<OT>Pascal has always had pointers.
CBFalconer said:I think there is something specific, but even if not, it is
certainly implied. For example, if p points to the last item in an
array, p++ is valid. p-- will then produce a valid dereferencable
pointer, while p = NULL; p-- will not.
Chris said:.... snip ...
(I really do have a "strictcc" command, too. Some might regard
it as cheating, but it works.)
>
> guess I'm getting forgetful in my old age. (haven't touched PASCAL in
> over 10tears). I thought PASCAL defined fixed ranges for the datatypes
> like integers. I guess I didn't port enough PASCAL applications to see
> the difference. (I could have swore you'd get an error on X=32767+2 ;
>
> Yes PASCAL and P-code, you have a point there, but I'm not sure it is
> in your favor.
> C->native assembler->program on native hardware
> Pascal->program in p-code-> runs in p-code interpreter
>
> The point is why even include this feature?
>
> So the PASCAL compiler was more advanced than the C compiler of the
> time. DO you think maybe it was due to PASCAL being a more abstract
> HLL than C might have had an effect here? (more likely though, it was
> PASCAL predated C, at least in widespread use.)
> Dik T. Winter wrote: ....
>
> Well you cannot, but those processors did not even exist when C was
> created. So those features didn't make it. To some degree, C is more of
> a PDP assembler.
Keith said:[...]Ed Prochak said:Keith Thompson wrote:
There's a continuum from raw machine language to very high-level
languages. Macro assembler is only a very small step up from
non-macro assembler. C is a *much* bigger step up from that. Some C
constructs may happen to map to single instructions for *some*
compiler/CPU combinations; they might map to multiple instructions, or
even none, for others. An assignment statement might copy a single
scalar value (integer, floating-point, or pointer) -- or it might copy
an entire structure; the C code looks the same, but the machine code
is radically different.
Using entirely arbitrary units of high-level-ness, I'd call machine
language close to 0, assembly language 10, macro assembler 15, and C
about 50. It might be useful to have something around 35 or so.
(This is, of course, mostly meaningless.)
Assembly language is usually untyped; types are specified by which
instruction you use, not by the types of the operands. C, by
contrast, associates types with variables. It often figures out how
to implement an operation based on the types of its operands, and many
operations are disallowed (assigning a floating-point value to a
pointer, for example).
I know the old joke that C combines the power of assembly language
with the flexibility of assembly language. I even think it's funny.
But it's not realistic, at least for C programmers who care about
writing good portable code.
Dik T. Winter said:How do you get access to the condition bits?
Mark F. Haigh said:Keith said:[...]Ed Prochak said:Keith Thompson wrote:There's a continuum from raw machine language to very high-level
languages. Macro assembler is only a very small step up from
non-macro assembler. C is a *much* bigger step up from that. Some C
constructs may happen to map to single instructions for *some*
compiler/CPU combinations; they might map to multiple instructions, or
even none, for others. An assignment statement might copy a single
scalar value (integer, floating-point, or pointer) -- or it might copy
an entire structure; the C code looks the same, but the machine code
is radically different.
Using entirely arbitrary units of high-level-ness, I'd call machine
language close to 0, assembly language 10, macro assembler 15, and C
about 50. It might be useful to have something around 35 or so.
(This is, of course, mostly meaningless.)
That's really interesting, because I have pondered the question and
answered it in nearly the same way. However, the conclusion I came to
is that C occupies a relatively large range in the continuum, not a
single point.
C dialects that accept inline assembly push the lower bound much lower
than it would otherwise be. Likewise, the wealth of freely-available C
libraries push the upper bound much further up. You can run a
real-world system written in C all the way from the top to the bottom--
from the GUI (GNOME, for example), to the kernel; from the compiler to
the shells and interpreters.
Keith said:Mark F. Haigh said:Keith said:Keith Thompson wrote:
[...]There's a continuum from raw machine language to very high-level
languages. Macro assembler is only a very small step up from
non-macro assembler. C is a *much* bigger step up from that. Some C
constructs may happen to map to single instructions for *some*
compiler/CPU combinations; they might map to multiple instructions, or
even none, for others. An assignment statement might copy a single
scalar value (integer, floating-point, or pointer) -- or it might copy
an entire structure; the C code looks the same, but the machine code
is radically different.
Using entirely arbitrary units of high-level-ness, I'd call machine
language close to 0, assembly language 10, macro assembler 15, and C
about 50. It might be useful to have something around 35 or so.
(This is, of course, mostly meaningless.)
That's really interesting, because I have pondered the question and
answered it in nearly the same way. However, the conclusion I came to
is that C occupies a relatively large range in the continuum, not a
single point.
C dialects that accept inline assembly push the lower bound much lower
than it would otherwise be. Likewise, the wealth of freely-available C
libraries push the upper bound much further up. You can run a
real-world system written in C all the way from the top to the bottom--
from the GUI (GNOME, for example), to the kernel; from the compiler to
the shells and interpreters.
Standard C doesn't accept inline assembly. If some particular
compiler does so, it's an extension -- and you might as well think of
it as an assembler that also accepts C syntax.
As far as libraries are concerned, most of them aren't part of
standard C either -- and they needn't be either implemented in, or
called from, C.
Mark F. Haigh said:Thank you, Captain Pedantic. Is that response to me or the masses of
corruptable youths eagerly waiting to sprinkle their code with inline
assembly?
If the former, then my point was that in the realm of C dialects,
Standard C (ideally) occupies a slowly expanding middle ground. If the
latter, then kids, listen to Keith, he's right.
Again, true, but oblique to the point that it is possible to run a
fully functional _modern_ system using only code written in C dialects.
I don't believe any other language "family" can boast this (for
currently available hardware).
I intended my first sentence as a joke, actually. I could only take theInteresting. I think you may have found a small flaw in the standard.
Keith said:Was that intended as an insult?
This discussion is cross-posted to three different newsgroups (and
it's been interesting in spite of that). I'm reading and writing this
in comp.lang.c, where we discuss the C programming language as defined
by the standards. The standard specifically allows extensions, and we
sometimes discuss the permitted nature of those extensions, but
details about particular extensions (such as inline assembly) are
considered off-topic.
Dik T. Winter said:How do you get access [from C] to the [hardware's] condition bits?
With the usual gay abandon about extensions, you might define a
variable in system space, say _ccd, to hold those bits. You
specify the conditions under which it is valid, such as immediately
after an expression with precisely two operands, preserved by use
of the comma operator. Then:
a = b + c, ccd = _ccd;
allows you to detect overflow and other evil things.
Dik T. Winter said:How do you get access [from C] to the [hardware's] condition bits?
With the usual gay abandon about extensions, you might define a
variable in system space, say _ccd, to hold those bits. You
specify the conditions under which it is valid, such as immediately
after an expression with precisely two operands, preserved by use
of the comma operator. Then:
a = b + c, ccd = _ccd;
allows you to detect overflow and other evil things.
This turns out not to work very well in Real Compilers. The reasons
are outlined rather nicely in the GCC documentation:
It is a natural idea to look for a way to give access to the condition
code left by the assembler instruction. However, when we attempted to
implement this, we found no way to make it work reliably. The problem
is that output operands might need reloading, which would result in
additional following "store" instructions. On most machines, these
instructions would alter the condition code before there was time to
test it. This problem doesn't arise for ordinary "test" and "compare"
instructions because they don't have any output operands.
Chris said:CBFalconer said:Dik T. Winter said:How do you get access [from C] to the [hardware's] condition bits?
With the usual gay abandon about extensions, you might define a
variable in system space, say _ccd, to hold those bits. You
specify the conditions under which it is valid, such as immediately
after an expression with precisely two operands, preserved by use
of the comma operator. Then:
a = b + c, ccd = _ccd;
allows you to detect overflow and other evil things.
This turns out not to work very well in Real Compilers. The reasons
are outlined rather nicely in the GCC documentation:
It is a natural idea to look for a way to give access to the condition
code left by the assembler instruction. However, when we attempted to
implement this, we found no way to make it work reliably. The problem
is that output operands might need reloading, which would result in
additional following "store" instructions. On most machines, these
instructions would alter the condition code before there was time to
test it. This problem doesn't arise for ordinary "test" and "compare"
instructions because they don't have any output operands.
For reasons similar to those described above, it is not possible to
give an assembler instruction access to the condition code left by
previous instructions.
(from <http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Extended-Asm.html>).
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.