www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/07/03/00:14:35

From: Jih-Shin Ho <u7711501 AT bicmos DOT ee DOT nctu DOT edu DOT tw>
Subject: Re: Problem with sizeof
To: mage AT eskimo DOT com (Joel Thornton)
Date: Sun, 3 Jul 94 12:00:07 WST
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp)

> 
> I am having a problem with sizeof ... Here is what I have <I am
> taking this from the book I am learning C out of>:
> /* day_mon3.c -- initializes 10 out of 12 elements */
> #include <stdio.h>
> int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
> int main(void)
> {
>     int index;
>     extern int days[];  /* optional declaration */
      ^^^^^^^^^^^^^^^^^
      Remove this line
The 'extern int days[]' declaration hides 'int days[]' outside main(), so
GCC doesn't know the dimension of days.

> Auto-saving...
>               done
>     for (index = 0; index < sizeof days / sizeof (int); index++)
>         printf("Month %d has %d days.\n", index + 1, days[index]);
>     return 0;
> }
> 
> Here is the output I get upon compilation:
> 
> day_mon3.c: In function `main':
> day_mon3.c:9: sizeof applied to an incomplete type
> 
> ?? What to do ??
> 
> This code compiles well under Microsoft C... help!
> 
> - Mm	<mage AT eskimo DOT com>
> 


  -- Jih-Shin Ho

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019