[cc65] extern const construct

From: Bruce & Ann Reidenbach <bereiden1gmail.com>
Date: 2010-08-23 16:19:27
It appears that cc65 does not allow for an "extern const" declaration
when the constant value is a part of the declaration.  I'm trying to
create a single .h file for my project that defines the constants in
one case and declares them in another, thusly:

in file.c:
----------------------------------------------
#define  _DEFINE_GLOBALS_
#include "file.h"

in all other .c files:
----------------------------------------------
#include "file.h"

and in file.h:
----------------------------------------------
#ifdef  _DEFINE_GLOBALS_
#define _GLOBAL_
#else
#define _GLOBAL_ extern
#endif

_GLOBAL_ const int foo = "bar";  //  This does not work when _GLOBAL_ = extern
_GLOBAL        int woof;         //  This works in both case

The declaration of extern const int foo = "bar"; results in a
compilation error.  If I set it up such that the constants are
declared in all files, I get the following warning from ld65:

     ld65.exe: Warning: Duplicate external identifier: `_foo'

However, even thought the linker detected multiple constant
definitions, I end up with multiple copies of the (same) constants in
the linked image.  If I define the constant in the other files as:

extern const int foo;

then everything works as desired (no compilation errors and a single
constant in the image).

I'm not sure what the position of the C standard is in this case, but
I would think this would be allowed.

Bruce
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Aug 23 16:19:55 2010

This archive was generated by hypermail 2.1.8 : 2010-08-23 16:19:59 CEST