I
Irrwahn Grausewitz
^Sidney Cadot said:A hybrid monster is heaving into view....
Integer main(input, output)
{
PrintLn('Hello World')
}
You forgot the period. ;-)
^Sidney Cadot said:A hybrid monster is heaving into view....
Integer main(input, output)
{
PrintLn('Hello World')
}
_____________________E. Robert Tisdale said:Michael said:[Are there any] features that the C specification currently lacks
and which may be included in some future standardization.
The future of C is C++. The question now is,
"Will any future C++ standard adopt the features introduced in C99?"
restricted pointers,
variable-length arrays,
etc.
Sidney Cadot said:A hybrid monster is heaving into view....
Integer main(input, output)
{
PrintLn('Hello World')
}
Especially this latter form is quite useful, expressing the idea that
'a' is to be used if it has a non-zero value, else use 'b' as a
fallback. This could be threaded, as in 'a ?: b ?: c'... I'd seriously
hope the next committee would consider this. This actually /is/ useful.
... The only processor I've seen that has this is the Philips
Trimedia, an embedded processor optimized for multimedia streaming. It's
a VLIW processors with five parallel instruction units. Branch
prediction failure rollback is quite expensive on these beasts.
E. Robert Tisdale said:Michael said:[Are there any] features that the C specification currently lacks
and which may be included in some future standardization.
The future of C is C++.
Malcolm said:Jack Klein said:I could wish that pigs had wings so they could fly, but unless I can
come up with at least some solid engineering plans that showed
feasibility and a favorable cost-benefit ration, I would not expect
anyone to take my wish seriously.
I think there are two to be made for templates. The weak case is that
often it is handy to write a function once with several types of
arguments. For instance swap() naturally lends itself to a template
implementation. So too does mean().
Personally I don't think these cases are common enough to justify a new
language feature, and also involve some subtle problems. For instance
mean() is fine for floats and doubles, but will usually break when fed a
char array, and could easily break with a short.
The stronger case is that the C++ standard template library allows client
code to do away with dynamic memory, and almost to do away with pointers.
[...]
E. Robert Tisdale said:Michael said:[Are there any] features that the C specification currently lacks
and which may be included in some future standardization.
The future of C is C++. The question now is,
"Will any future C++ standard adopt the features introduced in C99?"
restricted pointers,
variable-length arrays,
etc.
Well actually they probably will -- and it is in fact *that* which
will spell the final death nail to C99. Any good feature of C99 is
likely to be adopted by the C++ committee
In said:Right-o. How does one become a committee member?
... My idea was to convice one reader to convince one committee member
that it's worth promoting it.
At least about the stack-fault thing. That really ought to be fixed next
time 'round.
"We" don't, but maybe you do. Such implementations are among the
most important users of C today.
Paul said:spell the final death nail
Mark McIntyre said:*shrug*. I understand your point, but when in implementation-dependent
territory, its quite immaterial what ISO requires, its never going to
safely port anyway so abandon all hope, ye who enter here....
In said:It's better to write code that checks for INT32_MAX and uses int32_t, ^^^^^^^^^^^
relying a supplemental "inttypes.h" if necessary until you have access
to a true C99 implementation.
However, it's not completely wrong to use the other approach.
Sidney Cadot said:goose said:* triple-&& and triple-|| operators: &&& and ||| with
semantics like the 'and' and 'or' operators in python:
a &&& b ---> if (a) then b else a
a ||| b ---> if (a) then a else b
[snip]
result = a? b: 0; /* &&& */
ITYM a ? b : a
surely its the same thing ?
Eg.
a() ? b() : a()
is not equivalent to
a() ? b() : 0
if a() has side-effects.
Sidney Cadot said:I think C99 has come a long way to fix the most obvious problems in
C89 (and its predecessors).
[...] I for one would be happy if more compilers would
fully start to support C99, It will be a good day when I can actually
start to use many of the new features without having to worry about
portability too much, as is the current situation.
There's always some things that could be improved of course. My
personal wish-list would include (in no particular order):
* mandatory support for fixed-width integers (in C99, this is
optional).
* support for a "packed" attribute to structs, guaranteeing that no
padding occurs.
* upgraded status of enum types (they are currently quite
interchangeable with ints); deprecation of implicit casts from
int to enum (perhaps supported by a mandatory compiler warning).
* a clear statement concerning the minimal level of active function
calls invocations that an implementation needs to support.
Currently, recursive programs will stackfault at a certain point,
and this situation is not handled satisfactorily in the standard
(it is not adressed at all, that is), as far as I can tell.
* a library function that allows the retrieval of the size of a memory
block previously allocated using "malloc"/"calloc"/"realloc" and
friends.
* a #define'd constant in stdio.h that gives the maximal number of
characters that a "%p" format specifier can emit. Likewise, for
other format specifiers such as "%d" and the like.
* a printf format specifier for printing numbers in base-2.
* I think I would like to see a real string-type as a first-class
citizen in C, implemented as a native type. But this would open
up too big a can of worms, I am afraid, and a good case can be
made that this violates the principles of C too much (being a
low-level language and all).
* Normative statements on the upper-bound worst-case asymptotic
behavior of things like qsort() and bsearch() would be nice.
O(n*log(n)) for number-of-comparisons would be fine for qsort,
although I believe that would actually preclude a qsort()
implementation by means of the quicksort algorithm
* mandatory constants for many things that currently need to
be tested by autoconf and similar tools, e.g. endianness.
* deprecate trigraphs. Let's end the madness once and for all.
* a reliable and easy way to walk over all integers in a certain
interval, including the MAX value for that type, by means of a
for loop; eg., currently
for(unsigned i=0;i<=UINT_MAX;i++) ...
doesn't work as intended.
* a "reverse comma" type expression, for example denoted by
a reverse apastrophe, where the leftmost value is the value
of the entire expression, but the right-hand side is also
guaranteed to be executed.
* triple-&& and triple-|| operators: &&& and ||| with semantics
like the 'and' and 'or' operators in python:
a &&& b ---> if (a) then b else a
a ||| b ---> if (a) then a else b
(I think this is brilliant, and actually useful sometimes).
* a way to "bitwise invert" a variable without actually
assigning, complementing "&=", "|=", and friends.
* 'min' and 'max' operators (following gcc: ?< and ?>)
* a div and matching mod operator that round to -infinity,
to complement the current less useful semantics of rounding
towards zero.
Personally, I don't think it would be a good idea to have templates
in C, not even simple ones. This is bound to have quite complicated
semantics that I would not like to internalize.
As I understand it, it's a matter of having enough money and free time
on your hands.
Spend more time on comp.std.c and you won't be so optimistic. There are
huge loopholes in the current standard, inherited from the old standard
and no one wants to do anything to fix them. "It's not a problem in
practice" is the usual lame excuse.
goose said:no, but if a and b are not macros which expand to a() and b(), then
a ? b : 0
is identical to
a ? b : a
<nit>
the example code above did not actually state whether or not
macros were used, or if there were any side-effects.
it *did* however, use a and b, and not a() and b().
* support for a "packed" attribute to structs, guaranteeing that no
padding occurs.
Indeed, this is something I use on the x86 all the time. The problem
is that on platforms like UltraSparc or Alpha, this will either
inevitably lead to BUS errors, or extremely slow performing code.
If instead, the preprocessor were a lot more functional, then you
could simply extract packed offsets from a list of declarations and
literally plug them in as offsets into a char[] and do the slow memcpy
operations yourself.
I agree. Enums, as far as I can tell, are almost useless from a
compiler assisted code integrity point of view because of the
automatic coercion between ints and enums. Its almost not worth the
bothering to ever using an enum for any reason because of it.
That doesn't seem possible. The amount of "stack" that an
implementation might use for a given function is clearly not easy to
define. Better to just leave this loose.
Ah -- the kludge request. Rather than adding format specifiers one at
a time, why not instead add in a way of being able to plug in
programmer-defined format specifiers? I think people in general would
like to use printf for printing out more than just the base types in a
collection of just a few formats defined at the whims of some 70s UNIX
hackers. Why not be able to print out your data structures, or
relevant parts of them as you see fit?
This seems too esoteric.
Hmmm ... why not instead have ordinary operator overloading? While
this is sometimes a useful shorthand, I am sure that different
applications have different list cutesy compactions that would be
worth while instead of the one above.
Is a ~= a really that much of a burden to type?
As I mentioned above, you might as well have operator overloading instead.
Right -- this would just be making C into C++. Why not instead
dramatically improve the functionality of the preprocessor so that the
macro-like cobblings we put together in place of templates are
actually good for something? I've posted elsewhere about this, so I
won't go into details.
It has? I can't think of a single feature in C99 that would come as
anything relevant in any code I have ever written or will ever write
in the C with the exception of "restrict" and //-style comments.
[...] I for one would be happy if more compilers would
fully start to support C99, It will be a good day when I can actually
start to use many of the new features without having to worry about
portability too much, as is the current situation.
I don't think that day will ever come. In its totallity C99 is almost
completely worthless in real world environments. Vendors will be
smart to pick up restrict and few of the goodies in C99 and just stop
there.
Indeed, this is something I use on the x86 all the time. The problem
is that on platforms like UltraSparc or Alpha, this will either
inevitably lead to BUS errors, or extremely slow performing code.
If instead, the preprocessor were a lot more functional, then you
could simply extract packed offsets from a list of declarations and
literally plug them in as offsets into a char[] and do the slow memcpy
operations yourself.
I agree. Enums, as far as I can tell, are almost useless from a
compiler assisted code integrity point of view because of the
automatic coercion between ints and enums. Its almost not worth the
bothering to ever using an enum for any reason because of it.
Yes.
That doesn't seem possible. The amount of "stack" that an
implementation might use for a given function is clearly not easy to
define. Better to just leave this loose.
There's a lot more that you can do as well. Such as a tryexpand()
function which works like realloc except that it performs no action
except returning with some sort of error status if the block cannot be
resized without moving its base pointer. Further, one would like to
be able to manage *multiple* heaps, and have a freeall() function --
it would make the problem of memory leaks much more manageable for
many applications. It would almost make some cases enormously faster.
Ah -- the kludge request.
> Rather than adding format specifiers one at
a time, why not instead add in a way of being able to plug in
programmer-defined format specifiers?
> I think people in general would
like to use printf for printing out more than just the base types in a
collection of just a few formats defined at the whims of some 70s UNIX
hackers. Why not be able to print out your data structures, or
relevant parts of them as you see fit?
The problem is that real string handling requires memory handling.
The other primitive types in C are flat structures that are fixed
width. You either need something like C++'s constructor/destructor
semantics or automatic garbage collection otherwise you're going to
have some trouble with memory leaking.
With the restrictions of the C language, I think you are going to find
it hard to have even a language implemented primitive that takes you
anywhere beyond what I've done with the better string library, for
example (http://bstring.sf.net). But even with bstrlib, you need to
explicitely call bdestroy to clean up your bstrings.
I'd be all for adding bstrlib to the C standard, but I'm not sure its
necessary. Its totally portable and freely downloadable, without much
prospect for compiler implementors to improve upon it with any native
implementations, so it might just not matter.
Yeah, it would be nice to catch up to where the C++ people have gone
some years ago.
Anything that precludes the implementation of an actual quicksort
algorithm is a good thing. Saying Quicksort is O(n*log(n)) most of
the time is like saying Michael Jackson does not molest most of the
children in the US.
This seems too esoteric.
Hmmm ... why not instead have ordinary operator overloading?
While
this is sometimes a useful shorthand, I am sure that different
applications have different list cutesy compactions that would be
worth while instead of the one above.
Is a ~= a really that much of a burden to type?
As I mentioned above, you might as well have operator overloading instead.
Well ... but this is the very least of the kinds of arithmetic operator
extensions that one would want. A widening multiply operation is
almost *imperative*. It always floors me that other languages are not
picking this up. Nearly every modern microprocessor in existence has
a widening multiply operation -- because the CPU manufacturer *KNOW*
its necessary. And yet its not accessible from any language.
Probably because most languages have been written on top of C or C++.
> And what about a simple carry capturing addition?
Right -- this would just be making C into C++. Why not instead
dramatically improve the functionality of the preprocessor so that the
macro-like cobblings we put together in place of templates are
actually good for something? I've posted elsewhere about this, so I
won't go into details.
Paul said:.... snip ...
I agree. Enums, as far as I can tell, are almost useless from a
compiler assisted code integrity point of view because of the
automatic coercion between ints and enums. Its almost not worth the
bothering to ever using an enum for any reason because of it.
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.