[OCLUG-devel] one more question about structures...
Tim Thelin
tthelin at sbcglobal.net
Sun Jun 20 21:32:04 PDT 2004
James Colannino wrote:
> Christopher Smith wrote:
>
>> On Sat, 2004-06-19 at 18:32, James Colannino wrote:
>>
>>> Ok, I have one more question about structures... I hope that these
>>> three messages I've sent to the group in the past 30 minutes or so
>>> haven't gotten annoying. I haven't seen any activity on the
>>> oclug-devel list lately, so I'm hoping that at least people will be
>>> happy that there's some traffic :-P
>>>
>>> This isn't about anything going wrong. I'm just curious about a
>>> benign compiler warning that I'm getting. Consider the following code:
>>>
>>> #include <stdio.h>
>>>
>>> int main()
>>>
>>> {
>>> struct time {
>>> unsigned short int hour;
>>> unsigned short int min;
>>> };
>>>
>>> struct date_time {
>>> unsigned short int month; /* 1-12 */
>>> unsigned short int day; /* 1-31 */
>>> unsigned short int year;
>>>
>>> struct time time_of_day;
>>> } date;
>>>
>>> date.time_of_day.hour = 1;
>>>
>>> return 0;
>>> }
>>>
>>> Whenever I assign a value to a nested structure, I get the following
>>> warning from the compiler:
>>>
>>> warning: declaration does not declare anything
>>
>>
>>
>> Hmm... shouldn't it be:
>>
>> typedef struct date_time {
>> /* stuff */
>> } date;
>>
>> Does that make the compiler warning go away?
>
>
> Nope, that makes it compile with an error instead :-P What's weird is
> that the code I have above compiles with a warning on my laptop (but
> it still works), but not on my desktop machine. Weird...
>
> James
If you move your declaration of date to outside main(), does it compile
alright? It looks like your trying to declare an inline structure
without declaring the variable that will use the inline structure.
Or if your only going to use the structure once, try this:
struct date_time {
unsigned short int month; /* 1-12 */
unsigned short int day; /* 1-31 */
unsigned short int year;
struct {
unsigned short int hour;
unsigned short int min;
}time_of_day;
} date;
Btw, which line exactly is the warning occuring on?
Thanks,
Tim Thelin
More information about the OCLUG-devel
mailing list