#12 [RFC] deduplicate GetSystemXProp() code

open
nobody
None
5
2011-07-04
2011-07-04
Anonymous
No

A comment in galaxy.cpp hinted me into doing this "cleanup".
Does it looks sane enough ?

Please review, apply, comment...

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-07-04
     
  • Klauss++

    Klauss++ - 2011-07-21

    There's a syntax to initialize structures that has explicit field names.
    It would be better to use it in the defaults structure, since SystemInfo could eventually change (actually it's quite likely to change). With explicit field names, the compiler will issue errors and warnings.

    If you post an updated patch, I'll check a few things but I think this could go in. Without explicit field names it's a bit fragile and will introduce bugs whenever someone changes SystemInfo (since the compiler will happily ignore missing or mismatching fields in many situations).

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-07-25

    like that :
    struct point p = { .y = yvalue, .x = xvalue };
    http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Designated-Inits.html

    I couldn't get that kind of thing working in C++ wheareas in plain C it does...

    Is there something similar that could be used there ?
    https://sourceforge.net/u/stories/sell-games-online/?source=directory

     
    Last edit: lissacoffey 2015-08-30
  • Klauss++

    Klauss++ - 2011-07-26

    Pity.

    Then the other option is to do explicit assignments:

    static bool initialized = false;
    static struct point p;
    if (!initialized) {
    initialized = true;
    p.x = xvalue;
    p.y = yvalue;
    }

    It's not as pretty, but is safe from changes to the underlying struct.

     
  • Pheonix Rising

    Pheonix Rising - 2011-11-19

    klauss, does your last change look good enough for commit?

     
  • Klauss++

    Klauss++ - 2011-11-19

    If it builds, yes.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks