Wanna see something wierd?

Started by
19 comments, last by joanusdmentia 19 years, 4 months ago
The GCC team is a bit idiosyncratic when it comes to compiler extensions it would seem. As for the size issue, perhaps it is being silently converted into a unsigned integer?
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Advertisement
Our teacher told us that
	else if ( choice == 'D' ) {

is invalid in C, you will have to do:
	else           if ( choice == 'D' ) {

Well, at least in exams.
I don't know what's the different, maybe in the first C's it was invalid
pex.
Quote:Original post by pex22
Our teacher told us that
	else if ( choice == 'D' ) {

is invalid in C, you will have to do:
	else           if ( choice == 'D' ) {

Well, at least in exams.
I don't know what's the different, maybe in the first C's it was invalid


WTH? why? it sounds fishy. oh, well, i don't use c, so i can happily get on with else and its if on the same line (i'd actually define an elseif macro, but that's a bit much =)
@pex22
Both ways are perfectly legal. In fact, it doesn't matter what kind of whitespaces you use, it's all the same to the compiler.

[Edited by - Luctus on December 14, 2004 7:29:40 AM]
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
From gcc info-pages: "Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC accepts them in C89 mode and in C++. (However, GCC's implementation of variable-length arrays does not yet conform in detail to the ISO C99 standard.)"

These GNU extensions print warnings if -pedantic flag is used.. and if you really don't wan't to use those extension (by mistake) use -Werror flag in addition so your code does not even compile.
Quote:Original post by pex22
Our teacher told us that
	else if ( choice == 'D' ) {

is invalid in C, you will have to do:
	else           if ( choice == 'D' ) {

Well, at least in exams.
I don't know what's the different, maybe in the first C's it was invalid

Bull. Any undergrad compiler would be able to regard the two as the same.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
...it's just white space...should be fine.
http://edropple.com
As to the OP - I'm gonna have to third the 'doubleyew tee EFF?!' sentiment.

As for pex22's teacher - I'm guessing this is the same kind of academic ivory-tower bullcrap we got in uni. We actually lost marks for things such as putting in redundant brackets, despite the fact that such things are often aids to comprehension in the Real World(TM). In fact, the compiler I'm using at work at the moment won't allow you to use an operator sequence that's ambiguous to read, even though it as an unambiguous meaning in terms of C++'s left- and right-binding rules.
Quote:Original post by joanusdmentia
That's what I thought so I tried it myself. GCC 3.2 compiles it quite happily.

EDIT: The following code shows that the array is indeed dynamically allocated on the stack:

*** Source Snippet Removed ***
Oh far out, so it's like alloca then? I was thinking that it wouldn't work for globals anyway. Then there's structs containing the variable-size arrays, it can't merely be a pointer or you couldn't assign one struct to another to copy them etc. I can't imagine how they plan on fitting it into the language particularly nicely or consistently.

At this stage, with a not-fully supporting compiler, unportability, probably next to zero documentation or books on this method, the disadvantages compared to malloc etc, I suggest avoiding it, at least, for now.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
For everyone's benefit, the reason I provided this type of example instead of an malloc/free example was because the friend specifically asked me if it could be done this way.

Yes, malloc/free are the preferred way of doing things, but this is still perfectly valid.
=========================Buildium. Codium. Fragium.http://www.aklabs.net/=========================

This topic is closed to new replies.

Advertisement