473,387 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can I use C99 features yet?

Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.

Thanks,
Mike
Nov 14 '05 #1
18 1742
Michael B Allen <mb*****@ioplex.com> writes:
Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.


I'd say that there still aren't enough C99 implementations, if
you want your code to be portable.
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #2
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature? [...]
Yes. But in this newsgroup its more appropriate to talk about C99
(little more than a figment of some people's imagination) than Visual
C++ or gcc (one of which is almost certainly the compiler you are
using.)
[...] It has been almost 6 years right? [...]
I think technically just a little more than 5 years. But the major
contents were known for about 6 years.
[...] Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.


Oh well, sucks to be you. Maybe you could write a portable C
preprocessor with this extension yourself -- that would at least give
some reasonable prospect of portability. The C99 features are just not
portable (almost nobody implements it completely, and its highly
unlikely that any mainstream compiler ever will.) To be portable in C
you have to stick with the 16 year old standard, since the C standard
committee has generally been ignored since then.

Actually, if you are looking for adopting new language features (like
variadic macros) try pushing for them in the next *C++* standard, since
they will then be far more likely to be adopted (and possibly back
ported to the C compiler).

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 14 '05 #3
In message <pa*********************************@ioplex.com>
Michael B Allen <mb*****@ioplex.com> wrote:
Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.


Up to you. It depends whether the implementations you think you're likely to
use in the near future support the particular C99 feature you need.

We use C99 extensively here - mainly the core language stuff like designated
initialisers, VLAs, variadic macros and bool. Also <stdint.h> is very handy,
and snprintf. We use variadic macros for our debugging library.

However, we pretty much only use one compiler. The only other compiler we're
likely to use is gcc, which supports all or most of those features.

Any of the more esoteric stuff, particularly the math parts such as
<complex.h> and Annex F are likely to be far less portable. Most compilers
don't even provide C89 floating-point, let alone C99 Annex F.

Obviously any use of a C99 feature makes your code less portable than using
C89 features. But then, using C89 features makes your code less portable than
pcc code. It's up to you where you think the line should be drawn.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 14 '05 #4
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature? It has been almost 6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.


I've been told that C89 is a subset of C99, so if you stick to C89
rules, you are conforming to C99 (your program will work exactly the
same). I'm not sure if this is EXACTLY true (whether all C89 programs
will compile and then behave the same on a C99 compiler) but I presume
it is "for the most part" true because C89 is still popular (my IDE
doesn't even let me use // comments!)

C89 is a subset of C99
And neither are subsets of any C++ standard.

I think only gcc provides full C99 support.

Nov 14 '05 #5
On 2005-03-01 13:18:14 -0500, "TTroy" <ti*****@gmail.com> said:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.


I've been told that C89 is a subset of C99,


You've been told wrong.
so if you stick to C89
rules, you are conforming to C99 (your program will work exactly the
same). I'm not sure if this is EXACTLY true (whether all C89 programs
will compile and then behave the same on a C99 compiler) but I presume
it is "for the most part" true because C89 is still popular (my IDE
doesn't even let me use // comments!)


If C89 is a subset of C99 in the same way that C89 is a subset of C++
(i.e. it isn't). All three languages share many features, but none is a
true subset or superset of either of the others.

Valid C89, invalid C99, invalid C++:

#include <stdio.h>

foo()
{
return 20;
}

main()
{
printf("%d\n", foo());
return 0;
}

Invalid C89, valid C99, invalid C++:

#include <stdio.h>

int main()
{
for(long long i=0; i<50; ++i)
{
printf("%lld\n", i);
}
return 0;
}

--
Clark S. Cox, III
cl*******@gmail.com

Nov 14 '05 #6
TTroy wrote:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature?
No!
It has been almost 6 years right?
Specifically I'm interested in variadic macros.
All of my code is C89 (or less) except for my debugging macros.


I've been told that C89 is a subset of C99
so, if you stick to C89 rules, you are conforming to C99
(your program will work exactly the same).
I'm not sure if this is EXACTLY true (whether all C89 programs
will compile and then behave the same on a C99 compiler)
but I presume it is "for the most part" true
because C89 is still popular
(my IDE doesn't even let me use // comments!)

C89 is a subset of C99
and neither are subsets of any C++ standard.

I think only gcc provides full C99 support.


Not yet. Take a look at

Status of C99 features in GCC

http://gcc.gnu.org/c99status.html

It appears that about 75% of the new features are "done".
I don't care about any of the "missing" features.
None of the "library issues" concern me".
It bothers me that variable-length arrays,
complex (and imaginary) support, IEC 60559 support
and inline functions are "broken"
but I haven't had any trouble with them yet
so I'm not sure that I care about them either.

My conclusion is that
C99 support in GCC is "good enough" for me.

It would be nice to know if there is a subset of C99 features
which are supported well enough by most compilers
to ensure portability.
Nov 14 '05 #7
"TTroy" <ti*****@gmail.com> writes:
[...]
I think only gcc provides full C99 support.


No, gcc doesn't provide full C99 support.

<http://gcc.gnu.org/c99status.html>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
TTroy wrote:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature?

No!


It's a good idea if you can count on the feature being available in
all the implementations you need to use. It's potentially a bad idea
otherwise. A simple "yes" or "no" answer is misleading.

[snip]
My conclusion is that
C99 support in GCC is "good enough" for me.
And each project has to decide for itself whether it's "good enough"
for that project.
It would be nice to know if there is a subset of C99 features
which are supported well enough by most compilers
to ensure portability.


Agreed.

I believe there are some platforms that are not supported by gcc, and
on which the native compiler doesn't support C99 and is unlikely to in
the future. (I think Cray systems are an example, but I'm not sure of
the current status.) On the other hand, not everyone needs to care
about such platforms.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #9
Clark S. Cox III wrote:
On 2005-03-01 13:18:14 -0500, "TTroy" <ti*****@gmail.com> said:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of my code is C89 (or less) except for my debugging macros.


I've been told that C89 is a subset of C99,


You've been told wrong.
so if you stick to C89
rules, you are conforming to C99 (your program will work exactly the same). I'm not sure if this is EXACTLY true (whether all C89 programs will compile and then behave the same on a C99 compiler) but I presume it is "for the most part" true because C89 is still popular (my IDE doesn't even let me use // comments!)


If C89 is a subset of C99 in the same way that C89 is a subset of C++

(i.e. it isn't). All three languages share many features, but none is a true subset or superset of either of the others.

Valid C89, invalid C99, invalid C++:

#include <stdio.h>

foo()
{
return 20;
}

main()
{
printf("%d\n", foo());
return 0;
}

Yes, I already knew about this case. This was a feature in C89 that
provided backward compatibility to older programs, but the standard did
say these old declarations will probably be removed sometime in the
future. What I really meant is, C89 has a "full set of features" that
is a subset of C99. In your case above, the feature is "definition or
declaring a function" and there are two ways to do it, and one of the
ways is acceptable in C99 too (explicitly declaring everything). So
this doesn't take away from a feature, it just means there is an
alternative that will still allow someone to program C89 such that it
is the same in C99.

Invalid C89, valid C99, invalid C++:

Of course code can be invalid in C89 and valid in C99, because for the
most part, C99 is a superset of C89.

#include <stdio.h>

int main()
{
for(long long i=0; i<50; ++i)
{
printf("%lld\n", i);
}
return 0;
}


Yes, the addition of long long increases the set of available integral
types in C99. That still fits the "subset" notion (C89's types is a
subset of C99's types)

Nov 14 '05 #10
On 2005-03-01 15:06:47 -0500, "TTroy" <ti*****@gmail.com> said:
Clark S. Cox III wrote:
On 2005-03-01 13:18:14 -0500, "TTroy" <ti*****@gmail.com> said:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature? It has been
almost
6 years right? Specifically I'm interested in variadic macros. All of my code is C89 (or less) except for my debugging macros.
I've been told that C89 is a subset of C99,


You've been told wrong.
so if you stick to C89
rules, you are conforming to C99 (your program will work exactly the same). I'm not sure if this is EXACTLY true (whether all C89 programs will compile and then behave the same on a C99 compiler) but I presume it is "for the most part" true because C89 is still popular (my IDE doesn't even let me use // comments!)


If C89 is a subset of C99 in the same way that C89 is a subset of C++

(i.e. it isn't). All three languages share many features, but none is

a
true subset or superset of either of the others.

Valid C89, invalid C99, invalid C++:

#include <stdio.h>

foo()
{
return 20;
}

main()
{
printf("%d\n", foo());
return 0;
}


Yes, I already knew about this case. This was a feature in C89 that
provided backward compatibility to older programs, but the standard did
say these old declarations will probably be removed sometime in the
future. What I really meant is, C89 has a "full set of features" that
is a subset of C99. In your case above, the feature is "definition or
declaring a function" and there are two ways to do it, and one of the
ways is acceptable in C99 too (explicitly declaring everything). So
this doesn't take away from a feature, it just means there is an
alternative that will still allow someone to program C89 such that it
is the same in C99.


My point still stands that there exists a program that is valid C89,
but is not valid C99. Therefore, by definition, C89 cannot be a subset
of C90.

int main()
{
float inline = 15.0;
int restrict = inline * 0;

return restrict;
}

--
Clark S. Cox, III
cl*******@gmail.com

Nov 14 '05 #11
"Clark S. Cox III" wrote:

My point still stands that there exists a program that is valid C89,
but is not valid C99. Therefore, by definition, C89 cannot be a subset
of C90.


ITYM "of C99". :-)
Nov 14 '05 #12
Kevin Bracey wrote:
In message <pa*********************************@ioplex.com>
Michael B Allen <mb*****@ioplex.com> wrote:

Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.

Up to you. It depends whether the implementations you think you're likely to
use in the near future support the particular C99 feature you need.

We use C99 extensively here - mainly the core language stuff like designated
initialisers, VLAs, variadic macros and bool. Also <stdint.h> is very handy,
and snprintf. We use variadic macros for our debugging library.

However, we pretty much only use one compiler. The only other compiler we're
likely to use is gcc, which supports all or most of those features.

Any of the more esoteric stuff, particularly the math parts such as
<complex.h> and Annex F are likely to be far less portable. Most compilers
don't even provide C89 floating-point, let alone C99 Annex F.


If you want to try <complex.h> and Annex F, you can take a look at free
C/C++ interpreter ch. it runs in Windows, Linux, Solaris, HP-UX,
FreeBSD, Mac OS X and QNX.

http://www.softintegration.com/demos...ndard/c99.html

Also, there is an article published in DDJ about C99 numeric and its
implementation.
http://www.softintegration.com/docs/...aper/j_ddj.pdf

Obviously any use of a C99 feature makes your code less portable than using
C89 features. But then, using C89 features makes your code less portable than
pcc code. It's up to you where you think the line should be drawn.

Nov 14 '05 #13
E. Robert Tisdale wrote:
TTroy wrote:
Michael B Allen wrote:
Is it considered a bad idea to use a C99 only feature?

No!
It has been almost 6 years right?
Specifically I'm interested in variadic macros.
All of my code is C89 (or less) except for my debugging macros.

I've been told that C89 is a subset of C99
so, if you stick to C89 rules, you are conforming to C99
(your program will work exactly the same).
I'm not sure if this is EXACTLY true (whether all C89 programs
will compile and then behave the same on a C99 compiler)
but I presume it is "for the most part" true
because C89 is still popular
(my IDE doesn't even let me use // comments!)

C89 is a subset of C99
and neither are subsets of any C++ standard.

I think only gcc provides full C99 support.

Not yet. Take a look at

Status of C99 features in GCC

http://gcc.gnu.org/c99status.html

It appears that about 75% of the new features are "done".
I don't care about any of the "missing" features.
None of the "library issues" concern me".
It bothers me that variable-length arrays,
complex (and imaginary) support, IEC 60559 support
and inline functions are "broken"
but I haven't had any trouble with them yet


variable-length arrays (VLA) and complex are supported in C/C++
interpreter Ch. However, it is not a compiler.

The supported C99 features can be found at
http://www.softintegration.com/demos...ndard/c99.html

not sure if it is helpful.
so I'm not sure that I care about them either.

My conclusion is that
C99 support in GCC is "good enough" for me.

It would be nice to know if there is a subset of C99 features
which are supported well enough by most compilers
to ensure portability.

Nov 14 '05 #14
In article <2005030113440716807%clarkcox3@gmailcom>,
Clark S. Cox III <cl*******@gmail.com> wrote:
....
I've been told that C89 is a subset of C99,


You've been told wrong.
so if you stick to C89
rules, you are conforming to C99 (your program will work exactly the
same). I'm not sure if this is EXACTLY true (whether all C89 programs
will compile and then behave the same on a C99 compiler) but I presume
it is "for the most part" true because C89 is still popular (my IDE
doesn't even let me use // comments!)


If C89 is a subset of C99 in the same way that C89 is a subset of C++
(i.e. it isn't). All three languages share many features, but none is a
true subset or superset of either of the others.


In reality, you will never get a true subset relation in either direction
(and I am leaving C++ out of it for now, as it is, of course, OT), because
each new standard will always do both of the following:
1) Tighten up the syntax (thereby breaking some old programs)
2) Add new features (which obviously weren't present in earlier
versions)

Nov 14 '05 #15
In article <d0**********@yin.interaccess.com>,
ga*****@yin.interaccess.com says...
In reality, you will never get a true subset relation in either direction
(and I am leaving C++ out of it for now, as it is, of course, OT), because
each new standard will always do both of the following:
1) Tighten up the syntax (thereby breaking some old programs)
2) Add new features (which obviously weren't present in earlier
versions)


Shortly, if it hasn't practically happened already, whatever gcc will
accept will become "the C language standard". I know, heresy. End
of the world. Call in the national guard. The sheer volume of code
being written in it will make it a de facto standard the way MS
practices have been in the past (and very likely will continue).

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #16
nm
Ben Pfaff wrote:
Michael B Allen <mb*****@ioplex.com> writes:

Is it considered a bad idea to use a C99 only feature? It has been almost
6 years right? Specifically I'm interested in variadic macros. All of
my code is C89 (or less) except for my debugging macros.

I'd say that there still aren't enough C99 implementations, if
you want your code to be portable.


That's an opinion! No opinions here! That has nothing to do with how
the language works! Off topic! Off topic!
Nov 14 '05 #17
nm@e.com wrote:
Ben Pfaff wrote:
Michael B Allen <mb*****@ioplex.com> writes:
Is it considered a bad idea to use a C99 only feature? It has
been almost 6 years right? Specifically I'm interested in
variadic macros. All of my code is C89 (or less) except for my
debugging macros.


I'd say that there still aren't enough C99 implementations, if
you want your code to be portable.


That's an opinion! No opinions here! That has nothing to do
with how the language works! Off topic! Off topic!


Bravo. A well earned PLONK.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 14 '05 #18
nm@e.com wrote:
That's an opinion! No opinions here! That has nothing to do with how
the language works! Off topic! Off topic!


I always regret adding anyone to my killfile, but some people are so
stupid that I really have no choice.
*plonk*
Nov 14 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kl | last post by:
Hi, python is really easy to learn in my opinion. There are loads of tutorials/books on the web talking about the most common python features. The problem comes when they add something new to the...
18
by: 5460lqh | last post by:
who can tell me which two features in the C++ language are most usefule, and which two features that you think are the most over-rated or the most misused and why you think so? Thanks very much!
2
by: zhaoyandong | last post by:
One of my interviewers ask me "Two favorite features of C++, and over-rated, and misued features" Could anybody give me some advice on this? Thanks
8
by: Servé Lau | last post by:
I've read the new features that are coming to the next VC and they all sound fine. But I was missing new standard C++ features, will the features like export still not be implemented? What...
6
by: aron t | last post by:
Hi, I am good php programmer and want to learn asp.net. Can someone tell me what are the best and the worst features of ASP.NET? thanks
0
by: Shawn Cutter | last post by:
I am beginning work on a somewhat complex project and I need to decide what route to take before beginning the project. The main issue with this project is that it needs to be modular and support...
148
by: BillJosephson | last post by:
Want to do OOP. Does c++ have all the abilities of java, or is it some subset? Thanks...
7
by: Fister | last post by:
I'm reading Professional C# (Wrox) and stumbled across: "Some features are supported by.NET but not by C#, and you might be surprised to learn that some features of the C# language are not...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.