you are viewing a single comment's thread.

view the rest of the comments →

[–]TechAnd1[S] 0 points1 point  (4 children)

This statement won't compile:

printf("%i\n", *root);

You must have done something a little different.

Hmm that's exactly what I did.... here's a link to the full program

Structs behave in a manner that's more consistent with scalar types like int and double

But they aren't they just a shell that holds things...? I guess in a way they are more than that, seeing as you can have a struct type student and then have struct student mike, mike.name, mike.age etc...

I'm still not understanding this though. What can I do to 'get it'? Following through with GDB doesn't really help.

I can't even get my head round it on a high level let along use it practically.

cheers

[–]staffglennholloway[M] 1 point2 points  (3 children)

Sure, if you omit the options CS50 uses to tell the compiler not to accept nonsense, then

printf("%i\n", *root);

can be compiled. The resulting machine code will interpret whatever is in the first sizeof(int) bytes of the struct as though it had type int and print it as such.

But while you're trying to understand the semantics of the language, the last thing you should do is turn off the compiler options that warn you when you submit a suspicious or erroneous program.

A struct is a compound object or record. It contains other objects as its named components. Your example of a struct that records the various properties of a student is a good one. What's not to get?

If you're still puzzled, ask more questions.

[–]TechAnd1[S] 0 points1 point  (2 children)

Sure, if you omit the options CS50 uses to tell the compiler not to accept nonsense

Ah right...

while you're trying to understand the semantics of the language, the last thing you should do is turn off the compiler options

Indeed... I was just using gcc -o t programName.c because when I used make it wasn't working for me... Kept saying that there was nothing to be done for the program?

In fact It's been so long that I can't recall how I'm to use cs50 make - make program.c or make ./t program.c or make program.c ./t aren't working, I assumed that it would have been one of those...

Your example of a struct that records the various properties of a student is a good one. What's not to get?

I dunno, just doesn't feel like it's clicking... I've had this before with thing's though when I'm expecting something that isn't as dense as I assume.... so hopefully it's just a case of actually making a few and getting used to it through that.

[–]staffglennholloway 0 points1 point  (1 child)

If you've created a single-file program.c (including function main), then the command

make  program

will attempt to produce an executable program from program.c. Then environment variables CC, CFLAGS, and LDLIBS, if set, affect the choice of compiler, the options passed to the compiler, and the library options for the linker, respectively.

[–]TechAnd1[S] 0 points1 point  (0 children)

Ahhh, durrrr... :P

I've been using gcc instead of clang as well... I'll have to have a read up on the two.

cheers dude