C programming help!

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
Below is my code that just done halfway, I have issue calling out function_1, it just work within the void main part. Can anyone help to t/s ?thx alot in advance!!

Compile and link no problem/error reported? That's strange. :s22:
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Compile and link no problem/error reported? That's strange. :s22:

If you are referring to the function name, that is fine.

just like you put a expression "10;", it's fine in C

function name is a pointer to the function so statement expression like

function_1; only generate warning since it is unused. It is not an error.

But other parts of the codes might generate warnings depending on the leniency of the compiler.

To: TS

However there should be an error on forward declaration since the declaration of the function with the "struct library" before the declaration of the functions

There is also a struct declaration mistake

in C, structures MUST have the keyword "struct" used all the time

so "struct library" refers to a structure named "library"

But in the code , there wasn't a structure named "library" at all

Code:
typedef struct { ... } library;

The above did not create structure named "library" so "struct library" must not be used in the code

What is created above is a NEW TYPE onto an anonymous structure and the new type is named "library"

just like

Code:
typedef int _INT32;

This is to create a NEW TYPE named "_INT32" and the type of it is analogous to an existing type named "int"

For the code to be correct, the order matters

first "typedef struct { ... } library;" should happen before the declaration of the functions having arguments using the new type.

Hence it should be

Code:
typedef struct { ... } library;

void function_1(library);
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top