merc.h:1315: warning: 'int weapon_type(const char*)' hides constructor for 'stru

Posted by Robert Powell on Sun 25 Oct 2009 07:40 AM — 3 posts, 17,822 views.

Australia #0
I have enabled a whole suit of compiler flags to track things that might be annoying at some point, and i have this warning.

merc.h:1315: warning: 'int weapon_type(const char*)' hides constructor for 'struct weapon_type'


int	weapon_type ( const char* );

int weapon_type (const char *name)
{
    int type;
 
    for (type = 0; weapon_table[type].name != NULL; type++)
        if (LOWER(name[0]) == LOWER(weapon_table[type].name[0]) && !str_prefix(name,weapon_table[type].name))
            return weapon_table[type].type;
    return WEAPON_EXOTIC;
}



I do not understand the warning, could someone please explain whats going on with this, ROM is a nightmare ;)
Australia Forum Administrator #1
I can reproduce that warning with this snippet:


struct weapon_type
{
    char *  name;
    int  vnum;
    int  type;
    int  *gsn;
};

int weapon_type (const char *name)
{
  return 0;
}

int main (void)
{
  return 0;
}



Compiling gives:


$ g++ -Wshadow  test1.cpp

test1.cpp: In function ‘int weapon_type(const char*)’:
test1.cpp:10: warning: ‘int weapon_type(const char*)’ hides constructor for ‘struct weapon_type’


It is basically warning you that you have a structure, "weapon_type", and a function, "weapon_type", and that - although there is no clash of names because they are different types - once you declare the function it "hides" the declaration of the struct.

So, rename one of them.
Australia #2
Thanks Nick, i understand now, sometimes i wish the GCC guys would use less cryptic warning messages.