[wplug] Linux vs OS X version of GCC

O'Connor, Michael P. mpoconnor at switch.com
Thu Apr 20 09:12:40 EDT 2006


Here is something that should help.  Never rely on order of operations I
would write that line as 
----
int stringLgn = strlen(args[arg_count]);
args[arg_count][strinLgn] = 0;
arg_count++;
----
The same with math equations that you put in always use ( ) around what
you want, we all know that a * b + c and (a * b) + c SHOUD come out the
same, but also the ( ) makes it more readable if you ever have to come
back to it in the future or if some one else has to come back to it. 

Michael P. O'Connor
US&S 
Office: 412-688-2491 
Cell: 412-498-0667
mpoconnor at switch.com

-----Original Message-----
From: wplug-bounces+mpoconnor=switch.com at wplug.org
[mailto:wplug-bounces+mpoconnor=switch.com at wplug.org] On Behalf Of Logan
Sent: Thursday, April 20, 2006 1:31 AM
To: wplug at wplug.org
Subject: [wplug] Linux vs OS X version of GCC

For class, I've been using my OS X laptop to do a bunch of  
assignments, but a recent one had a Segmentation Fault when the  
professor ran it on the Linux server. We had to modify that lab, so I  
found the error, here's the offending line:

args[arg_count][strlen(args[arg_count++])] = 0;//null terminate (with  
a self-referential strlen())
	/* ok, here was the bug in Mac vs linux
	*  I had "args[arg_count++][strlen(args[arg_count])] = 0;"
	*  You can see the change above, apparently Linux increments my

arg_count before getting that second []
	*  and mac gets both [][] before incrementing arg_count.
	*  Either that, or it's gcc version 4.0.0 vs version 3.2.3.
	*  Thus Linux segfaults when we try to get
strlen(args[invalid]).
	*  I thought C was supposed to be portable. Who's correct here?
	*/

So which is correct? Or is this an ambiguity of C, that I should just  
avoid?
The code there works in both versions of gcc, so I suppose if I just  
increment on the second [] it's "portable enough" for class ;-)
I'd still like to know about the first argument bit though.

The Linux server runs gcc version 3.2.3 20030502 (Red Hat Linux  
3.2.3-54).
My Mac runs gcc version 4.0.0 20041026 (Apple Computer, Inc. build  
4061). - I believe that once warned me that this version generates  
broken code on occasion.

_______________________________________________
wplug mailing list
wplug at wplug.org
http://www.wplug.org/mailman/listinfo/wplug



More information about the wplug mailing list