[LAD] G++ trouble

Will J Godfrey WillGodfrey at musically.me.uk
Mon Nov 16 13:22:54 CET 2020

On Mon, 16 Nov 2020 13:02:03 +0100
Fons Adriaensen <fons at linuxaudio.org> wrote:

>On Mon, Nov 16, 2020 at 12:24:10PM +0100, Kjetil Matheussen wrote:
>> A common mistake in C is omitting extern when declaring a global
>> variable in a header file. If the header is included by several files
>> it results in multiple definitions of the same variable.  
>* I _do_ have 'extern' in the header file, and
>* the header file is included in only one .cc file.
>Using 'extern' in a _definition_ seems like a contradiction to me...
>So for now I assume it's a G++ bug.
>Thanks to both of you,

That's weird.

In GCC 8.3 doing that in a globally included header actually *creates* a
multiple definitions error!

#ifndef GLOBALS_H
#define GLOBALS_H

const unsigned int ADD_COLOUR = 0xdfafbf00; fine

extern const unsigned int ADD_COLOUR = 0xdfafbf00; boom!

It wasn't me! (Well actually, it probably was)

... the hard part is not dodging what life throws at you,
but trying to catch the good bits.

More information about the Linux-audio-dev mailing list