Sign in to follow this  
Xloner12

C Structure defined in H headers.

Recommended Posts

I figured this was a stupid problem so i put it here in the beginners fourm. Im declaring a struct in an h file called userProfile. adminOperations.h now when I make pointer to it in differnt prototypes in the sockOperations.h file my compiler throws a fit. Now ive been having differnt issues with this header file all related to this struct I just wanted to see if any one had any ideas as to what im doing. I mean I do the exact same thing to the FD SET struct and it works. So im at a loss. Let me know if you guys see any thing. error message is: [Warning] "struct userProfile" declared inside parameter list [Warning] its scope is only this definition or declaration, which is probably not what you want [Warning] "struct userProfile" declared inside parameter list adminOperations.h its where i declare the userProfile Struct thats giving me the problems.
[source lang=c]
/*==============================================================================
-------------------- Admin Operations Header               ----------------------
==============================================================================*/
#ifndef ADMINOPERATIONS_H
#define ADMINOPERATIONS_H

#define TAG 131

typedef struct userProfile
  {
    char userName[40];
    char passWord[20];
    int lineInConnection;
    int setupDone;
    int userColor;
  }userProfile;



int checkBuffer(SOCKET *clientSocket_PTR,char *recv_buffer_PTR);


#endif  
/*------------------------------------------------------------------------------*/

This is the sock header thats having so much trouble
[source lang=c]
/*==============================================================================
-------------------- Socket Operations Header               ----------------------
==============================================================================*/
#ifndef SOCKOPERATIONS_H
#define SOCKOPERATIONS_H

#define MAXSOCKETS 5
#define MAX_BUFFER 6000
#define READTRUE 130
#define USEREXIT 449

int socketListenStart(WSADATA *info_WSADATA_PTR,SOCKET *listenSocket_PTR,struct sockaddr_in *serverAddress_PTR);

int selectCheckOnListenSocket(struct fd_set *listenSocketSet_PTR,SOCKET *listenSocket_PTR,SOCKET *clientSocket_PTR,int *clientConnected_PTR,char *connectionMessage,struct userProfile *clientProfile_PTR);

int fdSetSetup(struct fd_set *SocketSet_PTR,SOCKET *Socket_PTR);

int selectCheckOnConnectedSocket(struct fd_set *clientSocketSet_PTR,SOCKET *clientSocket_PTR,char *recv_buffer_PTR);

int sendToSocket(SOCKET *clientSocket_PTR,char *recv_buffer_PTR);

int userExit(struct  userProfile *clientProfile_PTR,int *clientConnected_PTR,SOCKET *clientSocket_PTR,int closingConnection);

int connectToListenSocket(WSADATA *info_WSADATA_PTR,SOCKET *clientSocket_PTR,char *SERVERADDRESS_PTR,struct sockaddr_in *address_serverSocket_PTR);

int clientSend(SOCKET *clientSocket_PTR,char *send_buffer_PTR);

#endif  
/*------------------------------------------------------------------------------*/

Share this post


Link to post
Share on other sites
Just a quick note, the typedef allows you to omit the struct keyword when using the type, that is, you can write:

userProfile p;


instead of:

struct userProfile p;

Share this post


Link to post
Share on other sites
No i dont include adminOperations.h in anything but sockOperations.c

Also Ive tried to use userProfile instead of saying struct userProfile because of the typedef and it still gives me the errors. :(



Share this post


Link to post
Share on other sites
Quote:
No i dont include adminOperations.h in anything but sockOperations.c


As SiCrane pointed out, that's your problem. userProfile is defined in adminOperations.h, so if you don't include it, the compiler has no way of knowing what the struct looks like (this is also the reason for the typedef error).

That said, because you are only declaring pointers to the struct, you don't have to include adminOperations.h. You can use a forward declaration at the top of sockOperations.h:

struct userProfile;

If you also want to use a typedef, I think you should write:

struct userProfile;
typedef struct userProfile userProfile;

or something like that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this