Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ ROM ➜ Compiling the server ➜ merc.h:1315: warning: 'int weapon_type(const char*)' hides constructor for 'stru

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

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Robert Powell   Australia  (367 posts)  Bio
Date Sun 25 Oct 2009 07:40 AM (UTC)
Message
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 ;)

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 25 Oct 2009 08:12 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #2 on Sun 25 Oct 2009 10:43 PM (UTC)
Message
Thanks Nick, i understand now, sometimes i wish the GCC guys would use less cryptic warning messages.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,489 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.