Is C99 the final C?

M

Michael B.

I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.

Of course, I speak only of features in the spirit of C; something like
object-orientation, though a nice feature, does not belong in C.
Something like being able to #define a #define would be very handy,
though, e.g:

#define DECLARE_FOO(bar) #define FOO_bar_SOMETHING \
#define FOO_bar_SOMETHING_ELSE

I'm not sure whether the features of cpp are even included in the C
standard though (and GCC has definitely taken quite a nonstandard approach
with regards to certain token expansions and whatnot), but that's one area
of improvement I see.

I would also like to see something along the lines of C++ templating,
except without the really kludgy implementation that the C++ folks decided
to go to ( and without the OOP ).

.... Mike pauses for the sound of a thousand *plonks*

Templates save a lot of time when it comes to commonly-used data
structures, and as they are entirely implemented at compile-time and don't
include, by their definition, OOP (although they can be well suited to
it), I think they would be a nice addition and in the spirit of C.

Your thoughts? I'm sure there's some vitriol coming my way but I'm
prepared 8)
 
M

Morris Dovey

Michael said:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.

Of course there are. Can you imagine that people will /ever/ stop
fixing things just because they ain't broke?
 
G

glen herrmannsfeldt

Morris said:
Michael B. wrote:
Of course there are. Can you imagine that people will /ever/ stop fixing
things just because they ain't broke?

There was a quote some years ago, I believe by one of the authors of the
original Fortran compiler, though it is hard to verify the source.
Something like:

"I don't know what the language of the year 2000 will look like, but it
will be called Fortran." (That is from memory, hopefully it is close.)

There is now, I believe, a Fortran 2003 that has very little in common
with the Fortran of 1954 or so. What will C look like when it is 50
years old?

I might prefer a new language rather than an extension of an existing one.

-- glen
 
T

those who know me have no need of my name

in comp.lang.c i read:
Michael B. wrote:

Of course there are. Can you imagine that people will /ever/ stop
fixing things just because they ain't broke?

yes. (cf the pl/i standard)
 
T

those who know me have no need of my name

in comp.lang.c i read:
I'm not sure whether the features of cpp are even included in the C
standard

all of them.
I would also like to see something along the lines of C++ templating,
except without the really kludgy implementation that the C++ folks decided
to go to ( and without the OOP ).

hard to see how you can do this properly without a pile of other stuff, but
if you've got an idea that makes sense advance it here, or to your national
body and see if they like it. you could even get involved in the standards
process yourself, though that's costly and too often thankless.
 
J

Jack Klein

I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.

Wrong newsgroup, actually. The one that discusses the past, present,
and future of the C standard is
Of course, I speak only of features in the spirit of C; something like
object-orientation, though a nice feature, does not belong in C.
Something like being able to #define a #define would be very handy,
though, e.g:

#define DECLARE_FOO(bar) #define FOO_bar_SOMETHING \
#define FOO_bar_SOMETHING_ELSE

I strongly disagree. This sort of thing only obfuscates code and
makes maintenance a nightmare.
I'm not sure whether the features of cpp are even included in the C
standard though (and GCC has definitely taken quite a nonstandard approach
with regards to certain token expansions and whatnot), but that's one area
of improvement I see.

If you are not aware of what is or is not in the current C standard,
that severely reduces the worth of any suggestions you make about
future changes or additions to that standard. There are a few, but
only a few, things about the preprocessor that are unspecified by the
standard.
I would also like to see something along the lines of C++ templating,
except without the really kludgy implementation that the C++ folks decided
to go to ( and without the OOP ).

I would like to see the next standard mandate that the compiler
generate code to do exactly what I meant, even when the code I typed
does not match that meaning. Expressing a thought like the one you
did in the paragraph above is truly meaningless. Where is the
analysis about what effort it would take on the part of compiler
writers to add this feature to the language? What existing code what
it break or not break? Can you provide a sample implementation to
show how it would work?

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.
... Mike pauses for the sound of a thousand *plonks*

Sorry to disappoint you, but I don't plonk off-topic posters unless
they are persistently off-topic or insulting.
Templates save a lot of time when it comes to commonly-used data
structures, and as they are entirely implemented at compile-time and don't
include, by their definition, OOP (although they can be well suited to
it), I think they would be a nice addition and in the spirit of C.

Your thoughts? I'm sure there's some vitriol coming my way but I'm
prepared 8)

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
S

Sidney Cadot

Michael said:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.

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.

* some mandatory semantics for floating-points types; e.g. the assurance
that integers between certain limits can be represented exactly in the
FP types (with associated constants in limits.h)

* deprecation of implicit casts of fp-types to integer types (perhaps
supported by a mandatory compiler warning).

* deprecation of implicit casts of void* to other pointer types (perhaps
supported by a mandatory compiler warning). This is a desire not
likely to be shared by many here, though ;-)

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

These are just some thoughts. Maybe there are perfectly good reasons why
some of these are a bad idea, I would be interested to hear this.

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.

Best regards,

Sidney
 
A

Arthur J. O'Dwyer

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.

Agreed. Although besides the mixing of declarations and statements,
I can't think of any C99 features I *use* that are lacking in C90.
I think // comments are obscene; I have no use for variable-width
arrays; any time I need an exactly 32-bit integer type, I'm probably
not writing completely portably anyway and might as well use 'int'
itself; and so on.

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

This would make some platforms incompatible with C; up to this
point, C has never [to my knowledge] *required* any fixed-width
data types. How about those 9-bit-byte mainframes everyone likes
to bring up?
* support for a "packed" attribute to structs, guaranteeing that no
padding occurs.

Needs elaboration. As stated, this is flatly impossible. Even
on a vanilla Win/Intel platform,

struct { char c; double d; } x;

simply *cannot* be organized to completely avoid padding. Unless
you'd just allow the compiler to throw a warning saying "Whoops!
This struct can't be 'un-padded'!" But then you'd have implementation-
defined behavior, which is basically what we have in C99 anyway.
* some mandatory semantics for floating-points types; e.g. the assurance
that integers between certain limits can be represented exactly in the
FP types (with associated constants in limits.h)

This either already exists, or would require only a small change,
I think. FP types already have mantissa and exponent parts; all
this would require would be a standard minimum mantissa length.
* deprecation of implicit casts of fp-types to integer types (perhaps
supported by a mandatory compiler warning).

No such thing as an "implicit cast." And I really don't see
the point of this one, although I have vague recollections that
you don't like any of C's implicit conversions (you heretic
malloc-caster, you!). I think warnings about "possible loss of
data" or "wider type converted to shorter type" are QoI issues
at most.
* deprecation of implicit casts of void* to other pointer types (perhaps
supported by a mandatory compiler warning). This is a desire not
likely to be shared by many here, though ;-)

Right. Not least because it would break just about every
C program written in the last 10 years. And that's a somewhat
conservative estimate.
If you want Java, you know where to find it. One of the great
things about C is that it is (IMHO) more elegant than Java, with
the latter's uber-strict typing rules and plethora of casts.
Compare a C++ client program to a Java one sometime, and marvel
at the difference. (But that's just me, and it's OT here anyway.)
* 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).

Agreed, it would be nice for enums to be more "special." On
the other hand, the biggest use for enums is as a drop-in replacement
for #defined integer constants, and I don't want to lose that
capability. (Yes, "constant" consts would fix *that* problem, but
that would basically turn C compilers into C++ compilers on a
complexity scale. I like the clear-cut distinction C makes between
"objects" like 'const int foo' and "values" like 'enum { foo }',
if you see what I mean.)
* 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.

Agreed.
* a library function that allows the retrieval of the size of a memory
block previously allocated using "malloc"/"calloc"/"realloc" and
friends.

While this would be nice for newbies, it's redundant for Real
Programmers (tm) who know how to store numbers in variables, and
it would break lots of malloc implementations. I know, I've made
a couple. Not all the efficient malloc implementations actually
store the sizes of blocks anywhere.
Unless you think it would be acceptable for

msize(malloc(X)) > X

in some (or all) cases; then it'd still break libraries, but the
fix would be easier.
* 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.

Interesting idea. This would be useful.
* a printf format specifier for printing numbers in base-2.

This, on the other hand, is kind of silly. Couldn't you
just write your own two-line function to do this? And after
base-2, what's stopping you from demanding a printf() that
can handle base-4, or base-9, or base-247? I think this is
an idea whose time will never come.
(Not to mention all those Intro Programming instructors
who would have to find a new way of introducing recursion...)
* 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).

Yep.
* 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 :)

Given that the Standard gives minimum bounds on the size of
any array, any *specific* qsort() implementation is O(foo) by
definition, as one can write O(foo) <= C*foo for a specific,
but very large, value of C.
In other words, I bet you can't write a loophole-free version
of this idea. And with loopholes, it's not worth changing the
existing wording.
* mandatory constants for many things that currently need to
be tested by autoconf and similar tools, e.g. endianness.

Sounds good, until I consider that the Standard doesn't even
mandate that integers *be* stored in one endianness or the other.
Surely POSIX standardized this anyway, for those platforms that
care so awful much about it.
* deprecate trigraphs. Let's end the madness once and for all.

Haven't they been deprecated yet? ;-)
* 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.

What do you suggest? A new looping construct? :) This is
an artifact of the way C handles numbers, and it won't go away
by wishing. Better to use one of the myriad ways already
standardized, e.g.

i = 0;
do {
...
} while (++i != 0);

Ugly, but functional. And I'm sure this is a FAQ anyway.
* 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.

Where's the sequence point? How on earth would this
construct possibly be useful to anybody? And who uses the
reverse apostrophe character for anything, anyway? :)
* 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).

I think something like this is a GNU C extension; IIRC
they added a?>b for "max(a,b)". Anyway, I don't see the
advantage over

result = a? b: 0; /* &&& */
(result = a) && (result = b); /* ||| */

The second one is just about as cryptic...
* a way to "bitwise invert" a variable without actually
assigning, complementing "&=", "|=", and friends.

Huh? You want to add logical-negation and arithmetic-negation
"assignment operators" while you're at it? This is a purely
vanity "improvement"; all modern compilers contain optimizers
that can optimize "i = ~i" into the equivalent of "NOT EAX"
anyway. No need to make the code illegible too.
* 'min' and 'max' operators (following gcc: ?< and ?>)

Ditto the "Huh?" This is what functions were built to
do. You know, curly braces and all that? (Question for
those who know; Chris Torek, maybe?: Do any processors
incorporate 'min' and 'max' instructions, or is the ?<
operator going to get compiled into the same thing as the
function call (inlined), anyway?)
* a div and matching mod operator that round to -infinity,
to complement the current less useful semantics of rounding
towards zero.

I think the math library may already have these. If
not, then yes, this is a good idea.


my $.02,
-Arthur
 
T

those who know me have no need of my name

in said:
in comp.lang.c i read:
hard to see how you can do this properly without a pile of other stuff, but
if you've got an idea that makes sense advance it here,

oops, advance it in comp.std.c rather than here.
 
S

Simon Biber

Arthur J. O'Dwyer said:
Needs elaboration. As stated, this is flatly impossible.
Even on a vanilla Win/Intel platform,

struct { char c; double d; } x;

simply *cannot* be organized to completely avoid padding.
Unless you'd just allow the compiler to throw a warning
saying "Whoops! This struct can't be 'un-padded'!" But
then you'd have implementation-defined behavior, which is
basically what we have in C99 anyway.

Surely it is possible, if you add in extra code to handle a
memcpy to and from &x.d every time you read or write to the
unaligned x.d?

[snip]
* 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
(result = a) && (result = b); /* ||| */

Or just a ? a : b
 
T

those who know me have no need of my name

[fu-t set -- comp.lang.c isn't the right venue for this]

in comp.lang.c i read:[from sidney cadot's next-c wishlist:]

how would you feel if the standard required merely, say, 10? seriously,
that's the sort of value that would have to be present (if it were
acceptable at all), and with such a trivial number (so as not to exclude
embedded systems) you'll probably just ignore it on a `substantial' system.
Interesting idea. This would be useful.

i don't think it's too interesting -- %p might be altered by the current
locale, so the maximum would have to be something totally silly, which
would probably induce worse silliness in the code (presumptions that other
platforms were just as low or high). i like int m = snprintf(0,0,"%p",p);
if (0 < m) { char s[m+1] /* or malloc(m+1) et seq if allocation safety is
needed and there is a recovery path */; ... } just fine.
This, on the other hand, is kind of silly.

i do think that strto* handling arbitrary bases in [2,36] without any
corresponding tool to create strings is somewhat strange, there being other
(pseudo)symmetries. but i too have no need for the standard to demand that
such functions exist. strto* are in the standard so that their behavior
can be standardized, without which we'd be back to ato* which means we're
always trying to cope with each platform's notion of what to do on
overflow. but the hypothetical *tostr's and/or *printf conversion
specifiers wouldn't have that sort of problem, so there's not really any
need for them.
 
W

Walter

Sidney Cadot said:
* a printf format specifier for printing numbers in base-2.

Digital Mars C has supported this, %b, for nearly 20 years now! Base 2
integral constants are also supported with a leading 0b, as in:

0b0110 which is 6
* deprecate trigraphs. Let's end the madness once and for all.

Has anyone seen trigraphs in any real code that is not a test suite or a
teaching project? I doubt anyone would miss it.

-Walter
www.digitalmars.com Free C/C++/D compilers
 
S

Servé Lau

Michael B. said:
I would also like to see something along the lines of C++ templating,
except without the really kludgy implementation that the C++ folks decided
to go to ( and without the OOP ).

With that I don't agree. templates (and OO) should not be introduced in C.
If there would be one feature of C++ that I would like to see in C it would
be namespaces. namespaces encourage writing clearer names for identifiers
and they reduce accidental nameclashing. C will still be procedural only, no
existing code will be broken and it's more suitable for larger projects.
 
S

Sidney Cadot

Arthur said:
Agreed. Although besides the mixing of declarations and statements,
I can't think of any C99 features I *use* that are lacking in C90.
I think // comments are obscene; I have no use for variable-width
arrays; any time I need an exactly 32-bit integer type, I'm probably
not writing completely portably anyway and might as well use 'int'
itself; and so on.

I agree wholly on the // part, that's a C++-ism that I'd rather see
deprecated in the next standard ;-)

Variable-width arrays are nice for performance-critical code since they
can be allocated on the stack in a few clock-cycles, and their
deallocation is free on most architectures, whereas malloc()/free() may
be more expensive. I would be glad when the day arrives when I can start
using them.

As to the fixed-width types: there is quite an important area of
application that needs this, which is interpretation of binary protocols
and file formats (this constitutes a large part of the work I'm involved
with at the moment).
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).

This would make some platforms incompatible with C; up to this
point, C has never [to my knowledge] *required* any fixed-width
data types. How about those 9-bit-byte mainframes everyone likes
to bring up?

I think their main raison-d'etre at the moment is as serving as
counter-examples in c.l.c discussions. Perhaps it is time, in the next C
version, to mandate that CHAR_BIT==8. I don't know.
Needs elaboration. As stated, this is flatly impossible. Even
on a vanilla Win/Intel platform,

I don't see why. The only thing needed for this is that the target
architecture be able to adress things at the byte level.
struct { char c; double d; } x;

simply *cannot* be organized to completely avoid padding. Unless
you'd just allow the compiler to throw a warning saying "Whoops!
This struct can't be 'un-padded'!" But then you'd have implementation-
defined behavior, which is basically what we have in C99 anyway.

It can be done by emitting a lot of code, but this wouldn't be a
problem; you'd only use it for applications where access to an
externally defined packed-binary specification is important.
This either already exists, or would require only a small change,
I think. FP types already have mantissa and exponent parts; all
this would require would be a standard minimum mantissa length.

As far as I am aware, the C standard doesn't mandate that floating point
values use sign/exponent/mantissa form; a hitherto unknown good trick
could be discovered for representing fractional numbers today, and it
could be implemented in C I think. My proposal is to have at least
boundaries for integers that can be represented without loss of precision.
No such thing as an "implicit cast."

Obviously, some of the neurons in my head are stubbornly refusing to
reroute here. I'll have a serious talk with them about who's in charge
later on.

I meant "implicit conversions".
And I really don't see
the point of this one, although I have vague recollections that
you don't like any of C's implicit conversions (you heretic
malloc-caster, you!).

.... "Burn the malloc-casting witch! Burn!" ... :)
> I think warnings about "possible loss of data" or "wider type converted
> to shorter type" are QoI issues at most.

You are probably right, this would break a lot of code.
Right. Not least because it would break just about every
C program written in the last 10 years. And that's a somewhat
conservative estimate.

....Not my C programs, it wouldn't ;-) ... But yes, this is a pet
peeve related wish that will not easily come true.
If you want Java, you know where to find it. One of the great
things about C is that it is (IMHO) more elegant than Java, with
the latter's uber-strict typing rules and plethora of casts.

There's a lot about Java that I don't like, but I think its
type-strictness is better. A matter of taste, I think.
Compare a C++ client program to a Java one sometime, and marvel
at the difference. (But that's just me, and it's OT here anyway.)
Agreed, it would be nice for enums to be more "special." On
the other hand, the biggest use for enums is as a drop-in replacement
for #defined integer constants, and I don't want to lose that
capability. (Yes, "constant" consts would fix *that* problem, but
that would basically turn C compilers into C++ compilers on a
complexity scale.

The last statement I do not understand. Care to elaborate?
> I like the clear-cut distinction C makes between
"objects" like 'const int foo' and "values" like 'enum { foo }',
if you see what I mean.)

Yes, although I don't quite know if I agree.

Well, that was easy! Although it would be very hard to find a wording
that could fit the intent, it is too important an issue to be left
unhandled, I think.
While this would be nice for newbies, it's redundant for Real
Programmers (tm) who know how to store numbers in variables, and
it would break lots of malloc implementations. I know, I've made
a couple. Not all the efficient malloc implementations actually
store the sizes of blocks anywhere.
Unless you think it would be acceptable for

msize(malloc(X)) > X

in some (or all) cases; then it'd still break libraries, but the
fix would be easier.

Something like the latter would be fine. This is not a high-priority
thing for me, but I always consider it somewhat of a waste that I have
to store the number of available slots in a dynamically growing
(realloced) array, while the heap manager is doing the same thing behind
my back.
Interesting idea. This would be useful.

Think so. The "%p" identifier is not restricted in any way by the
current standard, (i.e., it might emit a zillion characters in
principle); I think that is an oversight.
This, on the other hand, is kind of silly.

Darn, I was doing quite well till here...
Couldn't you just write your own two-line function to do this?

Of course. But printf is such a convenient function, and it would be
very little effort to add binary support (like a %b specifier).
> And after base-2, what's stopping you from demanding a printf()
> that can handle base-4, or base-9, or base-247? I think this is
an idea whose time will never come.

Perhaps the "precision" field of a %b identifier could be used to
specify a base from 2--36, with 2 as default. Just brainstorming here
(effectively meaning you shouldn't be too harsh in your response).
(Not to mention all those Intro Programming instructors
who would have to find a new way of introducing recursion...)

They could always fall back on good old Fibonacci :)
Given that the Standard gives minimum bounds on the size of
any array, any *specific* qsort() implementation is O(foo) by
definition, as one can write O(foo) <= C*foo for a specific,
but very large, value of C.

I don't understand, unless you mean "maximum bounds" ?
In other words, I bet you can't write a loophole-free version
of this idea. And with loopholes, it's not worth changing the
existing wording.
Ok.
Sounds good, until I consider that the Standard doesn't even
mandate that integers *be* stored in one endianness or the other.

Alright, how about "precisely one of the following should be defined by
some_new_or_existing_header_file.h":

ENDIANNESS_LITTLE
ENDIANNESS_BIG
ENDIANNESS_IRREGULAR

This would cover 99% of cases in practice. At least I'd be able to write

#ifdef ENDIANNESS_IRREGULAR
#error "I'm sorry, this code only works on Big/Little Endian machines"
#endif
Surely POSIX standardized this anyway, for those platforms that
care so awful much about it.


Haven't they been deprecated yet? ;-)

De facto, yes. I have yet to see a C book that mentions trigraphs in a
way other than "don't use this, ever".

As a side note, one of the things that annoyed me to no end in C++ is
that not only it keeps trigraphs, but it worsens things by also defining
digraph (2-character) sequences. Yew!
What do you suggest? A new looping construct? :) This is
an artifact of the way C handles numbers, and it won't go away
by wishing. Better to use one of the myriad ways already
standardized, e.g.

i = 0;
do {
...
} while (++i != 0);

Ugly, but functional. And I'm sure this is a FAQ anyway.

This can work for unsigned types, but I'm not so sure if a similar thing
can work portably for signed types.
Where's the sequence point?

After the evaluation of the expression preceding the apastrophe.
How on earth would this construct possibly be useful to anybody?

(warning: C2017 code ahead...)

if (result=fopen("a","r") ` printf("result: %d\n", result))
{
...
}


......instead of.....


result=fopen("a","r");
printf("result: %d\n", result);
if (result)
{
...
}

You may wonder why the first form would be preferable to the second
form. Well for one thing, it's shorter, (basically the same rationale as
for having a comma operator) and it wouldn't suffer from two evaluations
of the first expression (which might change of the right expression has
side effects).
> And who uses the reverse apostrophe character for anything, anyway? :)

Nobody, yet. (Of course, we'd need another trigraph!).
I think something like this is a GNU C extension; IIRC
they added a?>b for "max(a,b)". Anyway, I don't see the
advantage over

result = a? b: 0; /* &&& */
(result = a) && (result = b); /* ||| */

The second one is just about as cryptic...

I take it you mean

a &&& b ---> a ? b : a
a ||| b ---> a ? a : b

This suffers from the fact that expression a possibly needs to be
evaluated twice, which I'd like to prevent.
Huh? You want to add logical-negation and arithmetic-negation
"assignment operators" while you're at it? This is a purely
vanity "improvement"; all modern compilers contain optimizers
that can optimize "i = ~i" into the equivalent of "NOT EAX"
anyway. No need to make the code illegible too.

Ok, you've conviced me. It always struck me as a bit irregular that it
isn't available but I can't come up with a clear syntax.
Ditto the "Huh?" This is what functions were built to
do.

Except that functions need typed versions for all parameters, whereas
operators may be overloaded. Clears up syntax a bit.
> You know, curly braces and all that? (Question for
those who know; Chris Torek, maybe?: Do any processors
incorporate 'min' and 'max' instructions,

Chris is the regular "weird architecture" expert, I take it?

From my own experience: the Philips Trimedia embedded processors have
"min" and "max" opcodes. This is basically because they are VLIW
processors that thrive on undisturbed pipeline execution. Having a
branch would halt all parallel execution, which is The One Thing To Avoid.

I would expect similar opcodes to exist in IA-64, but I don't know.
I think the math library may already have these. If
not, then yes, this is a good idea.

Thanks for the interesting points you raised. It's a nice enough subject
to think about isn't it...

Best regards,

Sidney
 
P

pete

Arthur said:
I think // comments are obscene; I have no use for variable-width
arrays; any time I need an exactly 32-bit integer type, I'm probably
not writing completely portably anyway and might as well use 'int'
itself; and so on.

'long' might be a better choice
for when you need an exactly 32-bit integer type.
 
S

Sidney Cadot

Walter said:
Digital Mars C has supported this, %b, for nearly 20 years now! Base 2
integral constants are also supported with a leading 0b, as in:

0b0110 which is 6

Something like that would be nice. Didn't know this compileer, pity it
only targets dos/wintel systems, but I'll check it out anyway.
Has anyone seen trigraphs in any real code that is not a test suite or a
teaching project? I doubt anyone would miss it.

.....Even the International Obfuscated C Code Contest has abolished it....

Regards,

Sidney
 
S

Servé Lau

Sidney Cadot said:
Variable-width arrays are nice for performance-critical code since they
can be allocated on the stack in a few clock-cycles, and their
deallocation is free on most architectures, whereas malloc()/free() may
be more expensive. I would be glad when the day arrives when I can start
using them.

What compiler do you use then that you can't use them?
 
S

Sidney Cadot

Servé Lau said:
What compiler do you use then that you can't use them?

I use gcc, mainly, but the software's users use a variety of systems
(mostly win32, Linux, Sun, HP, AIX, Irix, ...), and I cannot rely on
anything better than a C89 compiler to be available.

Best regards,

Sidney
 
M

Mark Gordon

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

This would make some platforms incompatible with C; up to this
point, C has never [to my knowledge] *required* any fixed-width
data types. How about those 9-bit-byte mainframes everyone likes
to bring up?

I think their main raison-d'etre at the moment is as serving as
counter-examples in c.l.c discussions. Perhaps it is time, in the next
C version, to mandate that CHAR_BIT==8. I don't know.

Definitely not. CHAR_BIT==9 may be rare these days, but CHAR_BIT==16 is
not once you start looking at DSP processors which often don't have the
ability to access less that 16 bits (or or) in one operation.

... "Burn the malloc-casting witch! Burn!" ... :)

Requiring a diagnostic (not necessarily an error) for using unprototyped
functions might be of help.

The last statement I do not understand. Care to elaborate?

Something like

fancy_enum { fred=32, george=23 } bar;
bar = fred;
bar++; /* bar nor equals george */

possibly?
This can work for unsigned types, but I'm not so sure if a similar
thing
can work portably for signed types.

<snip>

i=0;
while (1) {
/* do stuff */
if (i==INT_MAX) break; /* or whatever other MAX */
i++;
}

Even uglier but safe for signed types.
 
A

Arthur J. O'Dwyer

Surely it is possible, if you add in extra code to handle a
memcpy to and from &x.d every time you read or write to the
unaligned x.d?

I suppose that would be possible -- but it would be ugly and
inefficient, and might have odd interactions with 'volatile'.
Plus, you'd need to generate code and/or space for a "staging
area" for all these misaligned values (the targets of all these
memcpy's), and that would probably make things a little more
complicated for the linker -- which object file gets the "staging
area" and which just refer to it? or does each TU get a separate
staging area, which would be inefficient?
I just don't like it. :)

* 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

If a is non-zero, return b; else if a is zero, return a.
If a is non-zero, return b; else if a is zero, return 0.
Means the same thing, and my way doesn't have to evaluate
a two times, so it's macro-safe.
Or just a ? a : b

Ditto the above comment about macro-safety, although
I guess my way does evaluate 'result' twice. Bottom
line -- use whichever way makes the code do what you
want it to do. :) I don't think there's any need for
new operators here.
Oh, and just for kicks, note that the &&& operator
would break some [pathological] C code.

-Arthur
 

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
474,261
Messages
2,571,041
Members
48,769
Latest member
Clifft

Latest Threads

Top