extern const declaration 
Author Message
 extern const declaration

Hi,

        I have the following problem with extern declaration, and wonder
if anybody could help me:

        /* include file p.h*/
        typedef struct
                {
                int a;
                } A;
        /* module global.c */
        A a[] =
                {
                {1},
                {2},
                {3},
                {4},
                {5}
                };
        const int size_a = sizeof(a);

        /* module some.c */
        #include "p.h"

        extern A a[];           /* works */
        extern const int size_a; /* doesn't work */

The problem is, that the compiler complaints about a non initialized
const value. I presumed, that the const value is already initialized.
I don't want to use a define.

Thanks in advance.

Michael



Thu, 30 Dec 1999 03:00:00 GMT  
 extern const declaration

I don't think you need to use extern on a const.  Try it without the extern
and initialize it.  It should work...



Quote:
> Hi,

> The problem is, that the compiler complaints about a non initialized
> const value. I presumed, that the const value is already initialized.
> I don't want to use a define.



Fri, 31 Dec 1999 03:00:00 GMT  
 extern const declaration



Quote:
>Hi,

>        I have the following problem with extern declaration, and wonder
>if anybody could help me:

>        /* include file p.h*/
>        typedef struct
>                {
>                int a;
>                } A;
>        /* module global.c */
>        A a[] =
>                {
>                {1},
>                {2},
>                {3},
>                {4},
>                {5}
>                };
>        const int size_a = sizeof(a);

>        /* module some.c */
>        #include "p.h"

>        extern A a[];           /* works */
>        extern const int size_a; /* doesn't work */

>The problem is, that the compiler complaints about a non initialized
>const value. I presumed, that the const value is already initialized.

A compiler can of cource complain about anything it likes as long as it
actually compiles good code. In this case I'd agree that the complaint
is not sensible i.e. the compiler could be improved by complaining about
only a definition (i.e. not just a declaration).

Quote:
>I don't want to use a define.

If it doesn't prevent you compiling the code I guess it is something you
could live with. Given that the code is perfectly correct you could
report it to the compiler developer on the grounds of quality of
implementation, however if you need a quicker fix you'll have to do one of:

1. Find some compiler option that suppresses the diagnostic (if one exists)

2. Remove const from the declaration (and definition) and accept that you
   lose some protection for size_a.

3. Change to a different compiler.

--
-----------------------------------------


-----------------------------------------



Fri, 07 Jan 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Overridden extern const

2. "extern" and function declarations

3. extern declarations

4. extern declaration question?

5. size of array in extern declaration?

6. extern declaration and definition within the same translation unit

7. extern declarations in header files

8. extern declaration of struct

9. extern in function declarations?

10. New: Problem with extern declarations--- Help please!

11. Problem with extern declarations--- Help please!

12. [Fwd: Re: extern const in global variables]

 

 
Powered by phpBB® Forum Software