Posted By: serishema | Jun 5th, 2006 @ 11:01 AM
page 1 of 2
Comments: 47 | Views: 13422
serishema
serishema
The Last Hacker Chick
Who here does computer science? Who else here has noticed that computer science departments seem to run linux and that staff members hastle students with laptops who aren't running linux? One of my professors once claimed that gcc has better conformance to the ISO/ANSI C/C++ standards than Visual C++ which is not even true! gcc as far as i know doesn't support true multidimensional arrays.

eg int tictactoe[3,3]; 

Will not compile on gcc. (Okay i haven't actually checked and i haven't written unmanaged C++ code in 100 million years it could be a CLR thing don't flame me if i 'm wrong)
 
He also went so far as to claim that Visual C++ was the reason my program didn't work when he couldn't find my mistake, and i had indeed made a mistake, a classic dangling pointer.

I hate linux now, especially GCC and the lack of decent debugging in mono (I used to run FreeBSD and switched to windows because visual studio was so much better than what i'd been using, especially the debuggers) but it seems i can't win so i'm reluctantly installing linux on the virtual pc trial which it seems i'll most likely have to buy along with more ram to keep it happy since it seems to be working so far, unlike two different open source emulators that both crashed before they could get to the fedora core install screen.
Xaero_Vincent
Xaero_Vincent
Sexy me

GCC is partially or more compliant with the latest C99 ISO standards as is Open Watcom. Microsoft Visual C++ is not or at least not at this time.

 

serishema wrote:
gcc as far as i know doesn't support true multidimensional arrays.

eg int tictactoe[3,3]; 

Will not compile on gcc.


Yes it does.  And don't let one lecturer put you off, always handy to know how more than one compiler works.

Back in my undergrad days (99-03) I saw a revere trend, moving from Windows and Visual Studio 6 to more of a *nix/gcc direction which was in large part pushed by the desire to make their programming instruction less platform specific.

From the sounds of it though, there is a desire for more Windows centric stuff, especially in the area of .NET... unfortunately they do not have any teaching staff that know much about it (other than a couple VB teachers who teach VB.NET just the same way they did VB6)... so I’m slowly working on a proposition for a series of .NET related courses and me as an professor for them (and people around me wondered why I got my masters degree).

When it comes to decent debuggers under Linux... I don’t think many will argue with you on that, take a look at this blog post from Ben Goodger (one of the devs on Firefox) who gripes about the very same thing.

Cairo
Cairo
I want my waffle sundae, give me my carbs!
The nice thing about BSD and/or Linux in the academic setting is that you can see how it works -- you can learn from it. That's not possible with closed-source products, whether Windows, OSX (above the "Darwin" level), or AIX.

Xaero_Vincent
Xaero_Vincent
Sexy me
vistawillship wrote:

serishema wrote:  I hate linux now, especially GCC and the lack of decent debugging in mono (I used to run FreeBSD and switched to windows because visual studio was so much better than what i'd been using, especially the debuggers) but it seems i can't win so i'm reluctantly installing linux on the virtual pc trial which it seems i'll most likely have to buy along with more ram to keep it happy since it seems to be working so far, unlike two different open source emulators that both crashed before they could get to the fedora core install screen.
Wait until you see Vista! Then, like I said before, we can all put this Linux nonsense away for good. The Universities will be overrun with Windows, and the dissenting professors tossed out with all their Linux distros.



Vista,

You crack me up dude... all you do here is discriminate against Linux and Open-Source. They arent nearly as bad as you make them seem and it's only getting better with standards and good old compitition from the boys at Apple and Microsoft.


Regards,
Vincent
Maurits
Maurits
AKA Matthew van Eerde
serishema wrote:
One of my professors once claimed that gcc has better conformance to the ISO/ANSI C/C++ standards than Visual C++ which is not even true! gcc as far as i know doesn't support true multidimensional arrays.

eg int tictactoe[3,3];


Which C/C++ standard allows this syntax?
I'm on a CS degree but my Uni' has set the curriculum so that it suits realistic jobs, for a lot of it at least. Which means a higher emphasis on Windows/VC++/MFC/.Net/Java etc. There are a couple of units that cover UNIX in various forms but nothing deep and nothing (except the Java) *developee.

*(not a word)
serishema wrote:
And yes that was my mistake. By going
gcc -c -ansi -pedantic myfile.c i'm instructing the compiler to compile for the old C89 standard rather than the new one aren't I?


C90 you mean? Wink My copy of GCC says this when I ask it to be pedantic.

warning: ISO C90 forbids variable-size array `variable_size_array'

One reason to use GCC I guess would have been that it is freely available, but now that you can get Microsoft's C++ compiler it isn't really a good argument.  Of course we don't get to use cl on the mac.


Maurits wrote:

Which C/C++ standard allows this syntax?


I think C0X (and all of the others) define it as
   int tictactoe[3][3]

so it must be a compiler extension.
Xaero_Vincent
Xaero_Vincent
Sexy me
Rossj wrote:

serishema wrote:
And yes that was my mistake. By going
gcc -c -ansi -pedantic myfile.c i'm instructing the compiler to compile for the old C89 standard rather than the new one aren't I?


C90 you mean? Wink My copy of GCC says this when I ask it to be pedantic.

warning: ISO C90 forbids variable-size array `variable_size_array'

One reason to use GCC I guess would have been that it is freely available, but now that you can get Microsoft's C++ compiler it isn't really a good argument.  Of course we don't get to use cl on the mac.


Or compile your program into a 64 bit executable. Or did Microsoft add that into 2005 Express as well?
Maurits
Maurits
AKA Matthew van Eerde
Rossj wrote:

I think C0X (and all of the others) define it as
   int tictactoe[3][3]

so it must be a compiler extension.


I concur.  It seems to dangerously conflict with the comma operator.

$ cat test.c
#include <stdio.h>

int main(void) {
int tictactoe[3,3];
int i, j;

for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
                tictactoe[i,j] = i * 3 + j;
                printf("%d,%d: %d; ", i, j, i * 3 + j);
        }
        printf("\n");
}

printf("\n");

for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
                printf("%d,%d: %d; ", i, j, tictactoe[i,j]);
        }
        printf("\n");
}

return 0;
}

$ gcc -Wall --std=c99 test.c
test.c: In function `main':
test.c:4: warning: left-hand operand of comma expression has no effect
test.c:9: warning: left-hand operand of comma expression has no effect
test.c:19: warning: left-hand operand of comma expression has no effect
$ ./a.out
0,0: 0; 0,1: 1; 0,2: 2;
1,0: 3; 1,1: 4; 1,2: 5;
2,0: 6; 2,1: 7; 2,2: 8;

0,0: 6; 0,1: 7; 0,2: 8;
1,0: 6; 1,1: 7; 1,2: 8;
2,0: 6; 2,1: 7; 2,2: 8;

... so though gcc compiles this, it's just making a single-dimensional array with the last specified index.
I've noticed the faculty in my department still have a strong lean towards *nix, but they've never struck me as evenly remotely prejudiced as your prof seems to be. Mostly, I think, it has to do with what they're comfortable with. These people were educated in very Unix-centric environment, and so the know the system and its tools very well. I've often seen them get frustrated using Windows simply because it behaves differently--it certainly doesn't help that campus tech services imposes all sorts of rediculous defaults that make life difficult for anyone trying to get any work done.

(Honestly, the CS department should be allowed to administer their own systems--the current situation is equivalent to asking culinary students to be satisfied with Happy Meals.)

Certainly I'd never want to be in a department that focused on Windows to the exclusion of anything else, but it's always nice to open some people up to new ideas. Office 2007's new equation editor may even be enough to convince them to stop hand-coding Latex. Smiley
Maurits wrote:

... so though gcc compiles this, it's just making a single-dimensional array with the last specified index.


It's a good job that the syntax is so ugly I'd never use it, unlikely (fortunately and through sheer fluke) to be bitten by this one Smiley
Xaero_Vincent wrote:


GCC is partially or more compliant with the latest C99 ISO standards as is Open Watcom. Microsoft Visual C++ is not or at least not at this time.



VC++ is a C++ compiler not a C one, so that is hardly surprising. It is a more compliant C++ compiler than gcc .

Is far as academia goes, we have a few, er, enthusiastic Linux using profs, plus a few that will just complain about anything Microsoft related regardless of how appropriate it is. On the whole however, there is a largely pragmatic approach that using Windows just makes life easier. There are some tools that only run on it and very few that don't (and even those can be used remotely via X-Windows.) Previous attempts to provide a mix of systems just resulted in machines spending large periods of time idle, whilst students queue to use others.

In all honesty, half the problem with Linux from an academic point of view is its reliance on the command line. You'd be surprised at the number of CS who just find the whole idea to be totally alien, meaning that a lot of teaching time would end up being spent on the very basics. Whether or not thats a bad thing is another matter entirely...

Xaero_Vincent
Xaero_Vincent
Sexy me
AndyC wrote:

Xaero_Vincent wrote: 

GCC is partially or more compliant with the latest C99 ISO standards as is Open Watcom. Microsoft Visual C++ is not or at least not at this time.



VC++ is a C++ compiler not a C one, so that is hardly surprising. It is a more compliant C++ compiler than gcc .

Is far as academia goes, we have a few, er, enthusiastic Linux using profs, plus a few that will just complain about anything Microsoft related regardless of how appropriate it is. On the whole however, there is a largely pragmatic approach that using Windows just makes life easier. There are some tools that only run on it and very few that don't (and even those can be used remotely via X-Windows.) Previous attempts to provide a mix of systems just resulted in machines spending large periods of time idle, whilst students queue to use others.

In all honesty, half the problem with Linux from an academic point of view is its reliance on the command line. You'd be surprised at the number of CS who just find the whole idea to be totally alien, meaning that a lot of teaching time would end up being spent on the very basics. Whether or not thats a bad thing is another matter entirely...



Yeah...

I think the problem is.. Linux & BSD have more robust command-line tools than GUI ones. More GUI front-ends to these need to exist to make Linux equally functional from a GUI as with the terminal. I think things are slowly but surely improving in this area.

The opposite can be said about the current state of Windows. But PowerShell should bring a rich command-line experience for Vienna. So thats awesome news along with the new Windows Server Core.


Regards,
Vincent
There is always Open Watcom and the Intel compiler. And as a good result I've just found that the Intel compiler, now almost obviously, runs on OSX - but you won't be shipping a Universal with that.
You know, cl.exe and gcc aren't your only options for a compiler. Your MCU/MPU vendor probably offers a compiler too.

And you people are still hand coding software? What is this, 1995? Unless you are writting device drivers, nobody should hand code software.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
serishema wrote:
After not being able to find array[x,y] in the ISO99 C++ specification, only the more usual jagged array syntax i checked the msdn docs and it is indeed a microsoft specific and CLR specific extension. It would probably do me good to use more than one compiler and write unmanaged code occasionally.

When in doubt, use Comeau. If Comeau in strict mode doesn't compile something, then it isn't in the standard. It's that simple. Smiley

Also, I have found a lot of people at my university still think VC means VC6, and have little or no experience at all with later versions. VC6 was a terribly C++ compiler in terms of standards compliance, it's only VC7.1 and VC8 that are good at that. So if any of them make any claims with regard to how bad VC's compliance is, assume they're talking about VC6.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
Maurits wrote:
If you like the tictactoe[3,3] syntax, you could make a TwoDArray<T> class and implement

T& TwoDArray<T>::operator[](int i, int j) { ... } // for writing
T TwoDArray<T>::operator[](int i, int j) const { ... } // for reading
(Hopefully I put the const in the right place?)

It's in the right place, but you're potentially introducing a copy of T which for all you know might be huge or have a non-trivial copy-constructor. Or worse, it might have no public copy constructor, which would cause your code to not compile.

It's therefore a better idea to return a const T& for the const version of operator[].
Maurits
Maurits
AKA Matthew van Eerde
Sven Groot wrote:
It's therefore a better idea to return a const T& for the const version of operator[].


I think I understand...
const T& TwoDArray<T>::operator[](int i, int j) const { ... }

so

TwoDArray<char> tictactoe(3); // TwoDArray<T>(int) assumes a square

tictactoe[2,2] = 'X'; // uses non-const version
char c = tictactoe[0,1]; // uses const version

tictactoe[0,1] will return a const ref to whatever is stored there... which C++ will turn around and feed to the corresponding char(const char&) constructer, and use that to build c.

Refs are rather heavier than chars... so it might make sense to have a specialized
// note return type is char, not const char& (yes, I can get away with this)
char TwoDArray<char>::operator[](int i, int j) const { ... }

... assuming that the person playing tic-tac-toe is so quick to move that the reading becomes a bottleneck (say, WHOPR)
Maurits
Maurits
AKA Matthew van Eerde
If you like the tictactoe[3,3] syntax, you could make a TwoDArray<T> class and implement

T& TwoDArray<T>::operator[](int i, int j) { ... } // for writing
T TwoDArray<T>::operator[](int i, int j) const { ... } // for reading
(Hopefully I put the const in the right place?)
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
Maurits wrote:
char c = tictactoe[0,1]; // uses const version

Actually, no. The const version will only be used if the non-const version can't be used, i.e. if the variable itself is const. So while your code accesses the non-const version, if you do this:
void foo(const TwoDArray<char> &tictactoe)
{
   char c = tictactoe[0,1]; // now it uses the const version
}

See?

tictactoe[0,1] will return a const ref to whatever is stored there... which C++ will turn around and feed to the corresponding char(const char&) constructer, and use that to build c.
In theory, yes. Of course, char is a basic type and doesn't actually have a copy constructor. For char it likely doesn't matter whether you return const T& or just T, either way the compiler will likely optimize the extra action away. There will however be situations with heavier types where it won't be able to optimize away the copy with the T route so const T& will save you there.

If you follow the standard to the letter and don't optimize at all returning T would mean first the T instance would get copied to a temporary value for the return statement, then you would take a reference to that and pass it to the copy-ctor for the receiving variable. Most compilers will optimize away the temporary copy though.
serishema wrote:
...i'm reluctantly installing linux on the virtual pc trial which it seems i'll most likely have to buy along with more ram to keep it happy...


I believe you can legally download, install and use Virtual Server 2005 R2 for free:

http://www.microsoft.com/windowsserversystem/virtualserver/software/default.mspx

It is like virtual PC but as a windows service and for free.  You should be able to install linux on it as well (you can even mount the same virtual PC image you've already created).
page 1 of 2
Comments: 47 | Views: 13422
Microsoft Communities