PDA

View Full Version : Difference in compilers?


Coutsos
October 20th, 2005, 11:12 AM
Hello, world!

For a lab in my systems programming course we are asked to download and compile an example program (http://janus.newcs.uwindsor.ca/~hjin/256/labs/files/lab5/streamexample.c) and run it with a test file. However, when I tried to compile it on my laptop running Breezy (with build-essential package installed) I got a bunch of errors.

niko@ubuntu:~/Desktop$ gcc streamexample.c
streamexample.c: In function ‘main’:
streamexample.c:10: error: ‘struct _IO_FILE’ has no member named ‘_file’
streamexample.c:11: error: ‘struct _IO_FILE’ has no member named ‘_base’
streamexample.c:17: error: ‘struct _IO_FILE’ has no member named ‘_file’
streamexample.c:18: error: ‘struct _IO_FILE’ has no member named ‘_base’
streamexample.c:19: error: ‘struct _IO_FILE’ has no member named ‘_cnt’
streamexample.c:20: error: ‘struct _IO_FILE’ has no member named ‘_ptr’
streamexample.c:26: error: ‘struct _IO_FILE’ has no member named ‘_file’
streamexample.c:27: error: ‘struct _IO_FILE’ has no member named ‘_base’
streamexample.c:28: error: ‘struct _IO_FILE’ has no member named ‘_cnt’
streamexample.c:29: error: ‘struct _IO_FILE’ has no member named ‘_ptr’

Yet, compiling it from my account on the school's server was fine (also gcc). I guess that it's probably just a different version of gcc, but I was really hoping somebody could provide me with a better understanding of the problem. I'd really prefer to do my programming work on my own computer than be forced to use the ridiculously outdated software they provide us with.

If this isn't enough information to help you figure out the problem, please let me know what else you need (and preferrably how to get it!).

Thanks in advance!

-Nick

David Marrs
October 20th, 2005, 12:45 PM
I would guess that your school have added code to the stdio.h file that defines these member names. I get the same error message as you and a look through the stdio.h file confirms what the compiler says. Grep their stdio.h for _file, _base and the like and see what you find.

If their stdio is different, you could always copy it to your working directory and include it with the #include "stdio.h" line (ie. swap the <tags> for "quotes"). If it's not different then I'm as clueless as you are. :)

thumper
October 20th, 2005, 12:51 PM
Is your school using Linux or some other UNIX OS?

Coutsos
October 20th, 2005, 02:27 PM
Thanks for the help, David. This is pretty troubling that the stdio header seems to be... non standard?

As for the school, their servers are running Solaris. I don't know the details but it seems they've worked out a deal in which the university bends over and takes it from Sun in exchange for crappy equipment. :(

toojays
October 20th, 2005, 06:48 PM
The header is standard, but your code is using nonstandard features of the FILE struct. All those _variable names you have used are non-standard, and should not be used in portable code. I don't think it's really fair to blame Sun for this.

LordHunter317
October 20th, 2005, 07:49 PM
I don't think it's really fair to blame Sun for this.It's sun, so it's justified by their very nature. ;)

Coutsos
October 20th, 2005, 08:43 PM
Well, the thing about Sun didn't really have all that much to do with anything. I guess I just don't like them.

More importantly though, are there some standard variable names I can use instead? And if so, why would anybody want to change it?

LordHunter317
October 20th, 2005, 09:08 PM
Nope. The internals of FILE are a black box, AFAIK.

JmSchanck
October 20th, 2005, 10:55 PM
How are the internals black box? Check out libio.h. Look for _IO_FILE.

LordHunter317
October 20th, 2005, 11:27 PM
As in, without a portability library, you're not guaranted by any standard what the contents of a FILE strucutre are.

toojays
October 21st, 2005, 04:30 AM
To add to LordHunter317's comment: the fact that the structure members which you're trying to access start with an underscore should serve as a big "this is not portable" warning. It's conventional to name such things that way, because in C, you can't really hide them from the user without resorting to ugly casting tricks.

JmSchanck
October 21st, 2005, 03:43 PM
Sorry, I should have been more clear. I completely agree with it not having guaranteed portability, it's just that black box implies that libio.h is not viewable when in fact it is. This is more of a White Box case, If he wanted to he could easily go look at his copy of libio.h and alter the variable names in his program to work with it.

Doesn't really matter what jargon we use though, the points been made, the code isn't portable.

LordHunter317
October 21st, 2005, 04:18 PM
it's just that black box implies that libio.h is not viewable when in fact it is.No, it implies that you're not supposed to know or care about the contents of a FILE structure. Just because you can find out what is inside the black box doesn't change the fact the box is black.

Libio.h isn't portable anyway, so any attempt to use it in the name of portability carries no weight.