[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Templates and warning switches

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Templates and warning switches
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Mon 19 Sep 2005 02:39 AM (UTC)  quote  ]
Message
In the event someone more knowledgable than I cares to have a look, I submitted a bug to gcc about this issue: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23959

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Wed 07 Sep 2005 11:47 AM (UTC)  quote  ]
Message
Heh, I have no problem going over their bug list, and submitting the case if need be. You have a much shorter testcase to illustrate the problem than I do :) This would technically fall under a regression since it worked in previous versions of the compiler.

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 07 Sep 2005 06:56 AM (UTC)  quote  ]
Message
Interesting. I assumed (more out of hope than anything else) that you had an older version of gcc. I tried it on 4.0.1 and can confirm getting the same error, with the exact same code I posted. I tried putting the default: below the case: statements, but no luck.

It very well could be a bug. When I remove the template, it generates no error. Template support causes headaches and it wouldn't surprise me if there were an error, somewhere... Chances are that if "someone" ( :-) ) goes looking on their bug list, this might already be there.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Wed 07 Sep 2005 03:31 AM (UTC)  quote  ]
Message
The original function I modified had the continue statements there, I changed it after realizing they looked silly. It didn't make any difference at all with regard to this error.

I am using GCC 4.0.1 right now, so I guess I need to get this tested under an older version to see what kind of results come back from it. I do have to wonder if I've stumbled onto some kind of odd compiler bug :P

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Wed 07 Sep 2005 01:52 AM (UTC)  quote  ]
Message
Oh, right, but still, why would you put a continue there, when a break would work just as well? There's nothing after the switch statement, does it compile better?

Anyway, the 'more correct' way to use continues would be to include a break after the continue, for each case; this way if you want to remove the continue statement (for debugging, or if you want to do something after freeing memory) you'll still have the correct behavior (as opposed to deleting it once for ERROR_PROG and again for IN_FILE_PROG.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 07 Sep 2005 12:58 AM (UTC)  quote  ]
Message
If it's a switch statement in isolation, then sure, it's not valid... but this is a continue statement inside a switch inside a for loop, so it's perfectly valid.

It might just be a gcc bug that was fixed in later versions. I can't reproduce the error, but that doesn't necessarily say a lot since I didn't reproduce the entire situation.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Wed 07 Sep 2005 12:55 AM (UTC)  quote  ]
Message
continue (as opposed to break) is not a valid statement inside of a switch body. (why would you put a continue in there anyway?)

I'll bet the problem is with GCC expecting to see default after all the rest of the cases, which is customary, but (apparently) not required by the standard.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 06 Sep 2005 10:56 PM (UTC)  quote  ]

Amended on Tue 06 Sep 2005 10:57 PM (UTC) by David Haley

Message
OK... now I have this:

Quote:
#include <iostream>

using namespace std;

template <typename ArrayType>
void foo( ArrayType * arr )
{
    int i = 0;

    for ( ;; )
    {
        switch ( arr[i] )
        {
            default:
                cout << arr[i] << endl;
                break;

            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                cout << "woot" << endl;
                continue;
        }

        i++;
    }
}

int main()
{
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};

    foo<int>(arr);

    return 0;
}
Compiled with g++ version 3.4.2 on Cygwin:
Quote:
dhaley@muri5 ~
$ g++ -o test test.cpp -Wswitch-default -Wall --pedantic

dhaley@muri5 ~
$
Again, no warnings or errors.

You are right though that when I remove 'default' I definitely get the error.

What version of gcc are you using?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Dralnu   USA  (277 posts)  [Biography] bio
Date Tue 06 Sep 2005 10:53 PM (UTC)  quote  ]
Message
This may seem an odd place to ask this, but what would it take to convert C to C++? I'm thinking of moving over to C++ myself. Sorry this may be an odd place to ask, but since you're talking about it...
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Tue 06 Sep 2005 10:50 PM (UTC)  quote  ]
Message
I also tried with the pedantic flag, no difference. This template is the only thing it's complaining about. Your test isn't using a template, so I'm not surprised it worked. Take out your default: tag and retest, it should complain.

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 06 Sep 2005 10:37 PM (UTC)  quote  ]
Message
Yeah, I was talking about inheritance. There are some potential headaches but for this kind of relatively simple setup, it's not too bad.

As for the original problem, it's hard for me to replicate your situation exactly, but I tried the following:
Quote:

#include <iostream>

using namespace std;

int main()
{
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};

    int i = 0;

    for ( ;; )
    {
        switch ( arr[i] )
        {
            default:
                cout << arr[i] << endl;
                break;

            case 1:
            case 2:
            case 3:
            case 4:aybe your version of gcc is confused?
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                cout << "woot" << endl;
                continue;
        }

        i++;
    }

    return 0;
}
I then compiled with g++ version 3.4.2 on Cygwin:
Quote:
dhaley@muri5 ~
$ g++ -o test test.cpp -Wswitch-default -Wall --pedantic

dhaley@muri5 ~
$
No warnings or errors...

(OK, I know this isn't the most scientific of tests, since a lot of things are different, but still...)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Tue 06 Sep 2005 10:29 PM (UTC)  quote  ]

Amended on Tue 06 Sep 2005 10:40 PM (UTC) by Samson

Message
No, putting in breaks didn't change anything, it still complains.

As far as the superclass thing, ok, so you're talking about inheritence then. I haven't messed with that yet, but this looks like a good time to try I suppose. :)


EDIT:

Er... nevermind. I just remembered why this was done this way. mud_prog_data is all common to mobs/objs/rooms. It's the lists on each, mob_index, obj_index, and room_index that caused me to write this template.

prog_target is either a mob, obj, or room index. And if you look at how mprog_file_read is working, the function will attach multiple scripts to one of these from a single file, so intereting won't really help here.

I guess I'll just leave this warning switch out now that I've fixed all the other legitimate places it was complaining.

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 06 Sep 2005 09:46 PM (UTC)  quote  ]
Message
So putting in breaks worked? Funky. :) What version of gcc do you have?

Well, my guess is that you're trying to unify the handling of oprogs, mprogs and rprogs. What could be done is to have all three of those structures inherit from a single 'prog' structure, one that contains all common variables e.g. arglist, proglist, fileprog...

It's not a big deal, really. Personally I try to do that kind of thing just because it makes things more organized (IMO, at least).

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Tue 06 Sep 2005 09:36 PM (UTC)  quote  ]
Message
No, it didn't generate unreachable code warnings. And I had the default case under the other two before I posted. I've even changed the continue; statements to break; statements with no change. Maybe a compiler bug? :P

You mentioned this being better done with an object superclass. Could you explain that and provide an example?

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 06 Sep 2005 07:56 PM (UTC)  quote  ]
Message
That could be it, although I'd be a little surprised if the compiler was so 'silly' as to not "see" the default case. But, it's worth a try. But then will it generate unreachable code warnings? :P

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] 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.


6,807 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]