943,071 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 545
  • C RSS
Oct 30th, 2009
0

Problem with Structs

Expand Post »
After compiling the code found here, I immediately got a number of errors. (Unfortunately, Beej is the starting point my instructor suggested to implement our FTP client's "minimal" commands, but that's another story). Anyway, I got rid of a few of them, then ran into this:

  1. client.c:32 - error: storage size of 'hints' isn't known
  2.  
(It isn't actually on line 32 in Beej's guide, but it is one of the first lines of the main function - it's the one declaring the struct.)

So I looked up structs, and I saw that what Beej used is valid syntax for declaring a struct; however, the struct itself is not declared anywhere in the code. So I can only assume it is declared in a .h file or something, and I do not know how to get rid of that error. Any suggestions?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 30th, 2009
0
Re: Problem with Structs
Well, after reading Salem's response on another site (funny to run into Salem's post on another board from around two years ago, heh):

Quote originally posted by Salem From Another Site ...
Well goo.c has the actual structure, so there is no way for foo.c to know what the members are.

All that goo.h does is basically confirm that a struct called st exists.

In foo.c, you could have
t_st *var;
but you still would not be able to access any members within that struct.

It is, in other words an incomplete type.

Incomplete types are very useful for implementing opaque interfaces. goo.h declares an opaque pointer, which any user just sees the pointer.
The actual content of the struct is private to goo.c.

It's what FILE* should be - all user code just passes around a FILE* without ever knowing what is behind it.
I'm not sure how to proceed, but it is interesting. Doesn't that imply that one of my .h files that is included in my file contains an incomplete structure definition of addrinfo?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 30th, 2009
0
Re: Problem with Structs
Hi, I compiled that file (client) and I am not getting any error . !!!!!!
I used cc compiler and compiled on the following OS
  1. Linux mymachine 2.4.20-28.9.XFS1.3.1smp #1 SMP Mon Jan 5 13:20:15 CST 2004 i686 athlon i386 GNU/Linux
Reputation Points: 121
Solved Threads: 61
Posting Pro in Training
dkalita is offline Offline
402 posts
since Sep 2009
Oct 30th, 2009
0
Re: Problem with Structs
What. . ?

I compiled with gcc -ansi -Wall client.c and I'm getting all sorts of errors. I'm not really sure what I could be doing wrong. I must be doing something really stupid though, because I don't think anyone else is having trouble with it. (Either that or nobody else is using it. . but it is an appropriate starting point for implementing an FTP client that sends commands such as "USER" and "PWD" to a server, isn't it?)

Edit: I compiled without the -ansi option and I got no errors. I guess its been so long since I've programmed in C that I completely forgot what the -ansi option does, but I can look that up. Thanks for dealing with my posts/stupidity

Last edited by BestJewSinceJC; Oct 30th, 2009 at 2:44 am.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 30th, 2009
1
Re: Problem with Structs
remove the -ansi option while compilation. Just do
gcc -Wall client.c
Reputation Points: 121
Solved Threads: 61
Posting Pro in Training
dkalita is offline Offline
402 posts
since Sep 2009
Oct 30th, 2009
0
Re: Problem with Structs
Yeah, I already did that on a whim, and thanks for compiling and helping me out - much appreciated. But what does "-ansi" actually mean? When I took C programming we just memorized to use that flag - we were told what it meant - but I forgot not and I see it nowhere online. Hmm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 30th, 2009
0
Re: Problem with Structs
check the link:
http://tigcc.ticalc.org/doc/comopts.html
(search for ansi in it)

or read the gcc manual (man gcc).
The description is present there.
Reputation Points: 121
Solved Threads: 61
Posting Pro in Training
dkalita is offline Offline
402 posts
since Sep 2009
Oct 30th, 2009
0
Re: Problem with Structs
Ahh. That explains a lot. Thanks a lot, you've been extremely helpful.

P.S. for everyone's amusement, I've spent the last half hour trying to figure out why I kept getting "connection refused" from ftp.gl.umbc.edu and it turns out umbc.edu is completely down, so that might hold some answers. Debugging hell.... haha
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: How to put a full sentence into an array?
Next Thread in C Forum Timeline: C program for arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC