D
Default User
jacob said:In this group there is a bunch of people that call themselves
'regulars' that insist in something called "portability".
Please stop trolling the newsgroup.
Brian
jacob said:In this group there is a bunch of people that call themselves
'regulars' that insist in something called "portability".
jacob said:In this group there is a bunch of people that call themselves 'regulars'
that insist in something called "portability".
Why not use a wrapper function that will always do the right
thing?
One reasonable option may be to flush stdout before exiting the
program, then call ferror to check whether there was an error.
If there was, terminate the program with an error (after
attempting to report it to stderr).
Richard Heathfield a écrit :
True, C99 didn't really advance the language that much, but it has some
good points.
Anyway, if we are going to stick to standard C, let's agree
that standard C is Standard C as defined by the standards comitee.
// comments? More sugar. VLAs? More sugar.
And what do you have against sugar?
You drink your coffee without it?
I mean, C is just syntatic sugar for assembly language. Why
not program in assembly then?
Mixed declarations are a progress in the sense that they put the
declaration nearer the usage of the variable, what makes reading
the code much easier, specially in big functions.
True, big functions are surely not a bright idea, but they happen
I accept that this is not a revolution, or a really big progress in C
but it is a small step, what is not bad.
VLAs are a more substantial step since it allows to allocate precisely
the memory the program needs without having to over-allocate or risk
under allocating arrays.
Under C89 you have to either:
1) allocate memory with malloc
2) Decide a maximum size and declare a local array of that size.
Both solutions aren't specially good. The first one implies using malloc
with all associated hassle,
and the second risks allocating not enough
memory. C99 allows you to precisely allocate what you need and no more.
They do come handy, but again, they are not such a huge progress.
Maybe, maybe not, I have no data concerning this. In any case it
promotes portability (yes, I am not that stupid!
since it
defines a common interface for many math functions. Besides the control
you get from the abstracted FPU is very fine tuned.
You can portably set the rounding mode, for instance, and many other
things. In this sense the math library is quite a big step from C99.
That is a progress too, but (I do not know why) we never discuss them
in this group.
Maybe what frustrates me is that all this talk about "Stay in C89, C99
is not portable" is that it has taken me years of effort to implement
(and not all of it) C99
and that not even in this group, where we should
promote standard C C99 is accepted as what it is, the current standard.
I mean, each one of us has a picture of what C "should be". But if we
are going to get into *some* kind of consensus it must be the published
standard of the language, whether we like it or not.
For instance the fact that main() returns zero even if the programmer
doesn't specify it I find that an abomination. But I implemented that
because it is the standard even if I do not like it at all.
Ben Pfaff wrote (re. error checking of mallc):
That reminds me of the course where I learned C. The tutor advised:
#define MALLOC(type, n) ((type *)malloc((n) * sizeof(type))
Why not use a wrapper function that will always do the right
thing?
Keith said:I think you meant to drop the first "not" in that last sentence;
"people not being told" should be "people being told".
... What did C99 give us? Mixed declarations? Sugar. // comments?
More sugar.
VLAs? More sugar.
Compound literals - sure, they might come in handy one day.
A colossal math library? Hardly anyone needs it ...
(e-mail address removed) a écrit :
I implemented this by making the array a pointer, that
gets its value automagically when the function starts by making
a subtraction from the stack pointer. Essentially
int fn(int n)
{
int tab[n];
...
}
becomes
int fn(int n)
{
int *tab = alloca(n*sizeof(int));
}
The access is done like any other int *...
Did you have a test case for this code? If so, did you ever achieve
decision coverage in the case where ferror() gave an error? That would
be remarkable if you did, and I would like to hear how you did it.
... you cannot get rid of the name:
int *f(void) {
return (int []){ 1, 2, 3, 42 };
}
is not, because the anonymous array object vanishes. (You can,
however, make the array "const", provided the function returns
"const int *".)
Although again, those who want to write their Fortran code in C
will find it handy.
I don't understand why anyone would complain against standards.
Ben Pfaff wrote (re. error checking of mallc):
That reminds me of the course where I learned C. The tutor advised:
#define MALLOC(type, n) ((type *)malloc((n) * sizeof(type))
This is an unlikely definition. Try something like "most conforming tojacob said:In this group there is a bunch of people that call themselves 'regulars'
that insist in something called "portability".
Portability for them means the least common denominator.
Unless, of course, you know you are unlikely to deploy your app on theWrite your code so that it will compile in all old and broken
compilers, preferably in such a fashion that it can be moved with no
effort from the embedded system in the coffe machine to the 64 bit
processor in your desktop.
Unless, of course, you only cared about the C99 standard, in which caseSure, you can do that. But as you know, there is no free lunch.
You pay for that "portability" by missing all the progress done
since 1989 in C.
No one who knows what they are saying ever suggested otherwise, I'mNote that there is objectively speaking not a single useful
program in C that can be ported to all machines that run the
language.
Old Wolf said:That reminds me of the course where I learned C. The tutor advised:
#define MALLOC(type, n) ((type *)malloc((n) * sizeof(type))
jaysome said:Did you have a test case for this code? If so, did you ever achieve
decision coverage in the case where ferror() gave an error? That would
be remarkable if you did, and I would like to hear how you did it. The
only way I know how to do it is with preprocessor macros, and even
then it's not the greatest.
Richard Heathfield said:Ben Pfaff said:
Because "the right thing" depends on the situation. Simply aborting the
program is a student's way out. Unfortunately, the only worse "solution"
than aborting the program on malloc failure - i.e. not bothering to test at
all - is also the most common "solution", it seems.
Which standard? One can debate the pros and cons of any sort ofjacob said:Keith Thompson a écrit :
Well but this group is about STANDARD C or not?
Yes.
If we do not agree about what standard C is, we can use the standard.
Once we decide which of the major standards we are discussing, then youBut if we do not even agree what standard C is ther can't be
any kind of consensus in this group you see?
You seem to have an idee fixe that because there is more than oneThe talk about "Standard C" then, is just hollow words!!!
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.