Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Jabor posted:

What I was suggesting is that you run the test once to completion, take a heap snapshot, and then (on the same heap) run all your tests again and take a second snapshot afterwards. The idea is that the first test run forces all the lazy initialization to happen, so comparing the two snapshots allows to see everything that's leaking more memory every time it's run.

Oh I really did misunderstand you then. You're talking two runs of the test right next to each other. I presume I could do the same without comparing snapshots; just tell whatever I'm using to start caring only at the beginning of the second run, if that's possible.

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?
It turns out I'd forgotten a semicolon after the } at the end of my class definition.

raminasi
Jan 25, 2005

a last drink with no ice

hooah posted:

It turns out I'd forgotten a semicolon after the } at the end of my class definition.

MSVC 2010 at least usually at least warns for that - are you using an older version?

ether
May 20, 2001

GrumpyDoctor posted:

MSVC 2010 at least usually at least warns for that - are you using an older version?

MSVC 2010 does NOT warn you about that. Still bitter about the lost time (if you usually code in C# it simply seems right, which doesn't help)

Jewel
May 2, 2009

Can anyone actually tell me why functions and conditionals don't need the semicolon at the end of the brackets but classes and structs do?

Volte
Oct 4, 2004

woosh woosh

Jewel posted:

Can anyone actually tell me why functions and conditionals don't need the semicolon at the end of the brackets but classes and structs do?
Here's a C grammar: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html#declaration

To answer your question, the top level constructs in a translation unit are function definitions and declarations. Function definitions don't require one but declarations could be variable declarations, function declarations, and type declarations, and no matter which one it is, it's terminated by a semicolon. A struct block is actually a type itself, so you can do
code:
struct { int a; int b; } var;
According to that grammar (and tested with GCC) you can for some reason do this:
code:
const;
int;
typedef;

b0lt
Apr 29, 2005

Volte posted:

Here's a C grammar: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html#declaration

To answer your question, the top level constructs in a translation unit are function definitions and declarations. Function definitions don't require one but declarations could be variable declarations, function declarations, and type declarations, and no matter which one it is, it's terminated by a semicolon. A struct block is actually a type itself, so you can do
code:
struct { int a; int b; } var;
According to that grammar (and tested with GCC) you can for some reason do this:
code:
const;
int;
typedef;

Also, typedef is a storage class, so you can do int typedef foo; :haw:

raminasi
Jan 25, 2005

a last drink with no ice

ether posted:

MSVC 2010 does NOT warn you about that. Still bitter about the lost time (if you usually code in C# it simply seems right, which doesn't help)

It doesn't specifically warn you about missing semicolons after class definitions, but if it thinks an error was caused by a previously missing semicolon it will tell you sometimes. I'm 100% certain this has happened to me.

Morham
Jun 4, 2007
So I ported my guess the number game to C++ just for fun, I popped it all on Codepad so you guys can critique my readability and technique.

I know about the whole directives/declarations so I am aware I didn't have to write out the "std::" a billion times but I did. Also I curly brace all my decision statements out of habit from coding in AS2 for a while, plus I find it helps me read code better. I am going to work through the rest of this book which takes me through STL, Functions, References, Pointers, Classes, Inheritance and Polymorphism. After that I want to move into graphics and stuff (cliché'd goal of making a game), do people have a next best step?

All my previous game making experience is in unfinished ActionScript 2.0 projects, so I am familiar with OOP principles, but unfamiliar with its implementation without the crutch of a graphical interface.

shrughes
Oct 11, 2008

(call/cc call/cc)
Don't use global variables, use local variables, declared as close as possible to where they're used.

Your if (playerGuess < randomNumber) { ... } else if (playerGuess > randomNumber) { ... } else if (playerGuess == randomNumber) { ... } construct, I would write if (playerGuess < randomNumber) { ... } else if (playerGuess > randomNumber) { ... } else { ... }. The last comparison is redundant, but the reason to write it that way isn't performance, or to make the code smaller -- it's so that people reading the code can then see from the structure of the code that all the cases are covered -- that one of the branches will be taken. The way you write it, it makes it seem plausible that none of the branches might sometimes be taken.

I also don't like the way your "Would you like to play again?" loop is written. It redundantly encodes the rule that three are three kinds of answer values: 'y', 'n', and other values. It does this once in the condition of the while loop and once when deciding whether to set quit to true or false. Instead, I would have a separate boolean variable to specify whether to continue looping. Or, I would use `while (true)` and then use break; statements in the right place. This way, you don't have to worry about keeping the two things in sync when editing the code. Or maybe I would keep that loop the way you've written it, because in this case it's small and simple enough, so the mental cost of having an extra "done" variable is not offset by the meager benefit of making it more difficult to mess up when changing the loop's behavior.

Also, you end up reseeding the random number generator every game. You're only supposed to do that once per process, unless you have a specific reason to play with its seed value.

So I would write it this way:

http://codepad.org/idezeCxy

shrughes fucked around with this message at 12:12 on Jun 3, 2013

hooah
Feb 6, 2006
WTF?
I'm learning about while and do...while loops, and can't get the following program to quit when I enter 'q' or 'Q' unless I uncomment out the lines near the end of main. Why is that? The program hits the cout << choice line and correctly displays Q for the choice.

http://codepad.org/4dikW77Q

pseudorandom name
May 6, 2007

hooah posted:

I'm learning about while and do...while loops, and can't get the following program to quit when I enter 'q' or 'Q' unless I uncomment out the lines near the end of main. Why is that? The program hits the cout << choice line and correctly displays Q for the choice.

http://codepad.org/4dikW77Q

You have two different variables named choice in your main function, the inner-most variable is shadowing the outer variable.

edit: Visual C++ won't warn about this unless you have Visual Studio Premium or Ultimate and enable Code Analysis for C/C++.

gcc and clang have -Wshadow

pseudorandom name fucked around with this message at 18:45 on Jun 4, 2013

b0lt
Apr 29, 2005

hooah posted:

I'm learning about while and do...while loops, and can't get the following program to quit when I enter 'q' or 'Q' unless I uncomment out the lines near the end of main. Why is that? The program hits the cout << choice line and correctly displays Q for the choice.

http://codepad.org/4dikW77Q

You're shadowing the original choice variable with the one you're declaring inside the loop. The while condition is referring to the one declared at line 22, which never changes.

e:f;b

hooah
Feb 6, 2006
WTF?
Thanks, guys. I'd added the declaration because I was getting an undeclared identifier error, but now I see that I re-declared choice when I set it equal to the return from choose. Removed "char" and everything works fine.

Posting Principle
Dec 10, 2011

by Ralp
Can anyone recommend a good, simple build system? I've tried Premake but its missing things like post build commands.

b0lt
Apr 29, 2005

Jerry SanDisky posted:

Can anyone recommend a good, simple build system? I've tried Premake but its missing things like post build commands.

cmake

Posting Principle
Dec 10, 2011

by Ralp
Does cmake still require a file in every source directory?

e: vvv well then time to trudge through cmake docs

Posting Principle fucked around with this message at 19:44 on Jun 4, 2013

Dicky B
Mar 23, 2004

You only need one CMakeLists.txt per project.

xgalaxy
Jan 27, 2004
i write code
I was a big fan of premake but development is slow.
I just bit the bullet and started using cmake myself.
I hate it, but at least it works.

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

xgalaxy posted:

I was a big fan of premake but development is slow.
I just bit the bullet and started using cmake myself.
I hate it, but at least it works.

The key to writing cmake build scripts (so that you don't lose your sanity) is to not use any programming construct outside of an if-endif (and try not to havemore than one level of nesting) unless you are writing a new feature, in which case Dijkstra save you. Once you get used to writing one command per line, it becomes a lot easier to read your own build script to decipher just what is happening when you mess up (which you will)

Posting Principle
Dec 10, 2011

by Ralp
So is there a good "Cmake for people with severe mental retardation" tutorial other than the official one? I'm coming from Autotools, so anything that is friendlier than that will work.

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

Jerry SanDisky posted:

So is there a good "Cmake for people with severe mental retardation" tutorial other than the official one? I'm coming from Autotools, so anything that is friendlier than that will work.

Unfortunately, not really. There's the CMake Wiki, and the documentation. Once you understand the language that *should* be enough to get you moving forward (it just becomes a matter of reading the documentation and sometimes tinkering with configure runs to make sure it does what you think it does). The language tutorial they have is decent enough for what it is, and the language works almost like tcl (I say almost because you can't put hyphens in your function/macro names).

Also, all the commands and macros are case insensitive, so if you see a tutorial or script doing

code:
IF(SOME_VAR_THAT_IS_DEFINED_AND_IS_VERY_LARGE)
 SET(SOME_MORE_STUFF_BECAUSE_IF_IT_AINT_CAPS_IT_AINT_SHIT )
ENDIF()
You can ignore the upper case commands and it will work just fine, and be a heck of a lot more readable. Someone (hopefully not me) should write a better CMake tutorial, because as it is it's hard to hit the ground running without any experience with it.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I love a custom macro language specified by the hacked together regex replaces it uses to parse it. It just makes my day, I tell ya.

FlapYoJacks
Feb 12, 2009

SAHChandler posted:

Unfortunately, not really. There's the CMake Wiki, and the documentation. Once you understand the language that *should* be enough to get you moving forward (it just becomes a matter of reading the documentation and sometimes tinkering with configure runs to make sure it does what you think it does). The language tutorial they have is decent enough for what it is, and the language works almost like tcl (I say almost because you can't put hyphens in your function/macro names).

Also, all the commands and macros are case insensitive, so if you see a tutorial or script doing

code:
IF(SOME_VAR_THAT_IS_DEFINED_AND_IS_VERY_LARGE)
 SET(SOME_MORE_STUFF_BECAUSE_IF_IT_AINT_CAPS_IT_AINT_SHIT )
ENDIF()
You can ignore the upper case commands and it will work just fine, and be a heck of a lot more readable. Someone (hopefully not me) should write a better CMake tutorial, because as it is it's hard to hit the ground running without any experience with it.

I generally use caps with macros and enums only. Local variables get lowercase, and objects get Uppercase (Object.ButtFarts). It's all incredibly consistant so it's easy to see what's what right away.

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

ratbert90 posted:

I generally use caps with macros and enums only. Local variables get lowercase, and objects get Uppercase (Object.ButtFarts). It's all incredibly consistant so it's easy to see what's what right away.

This is cmake, not c or c++. It has two types. String, and string with a semicolon, which denotes a list. I'm not a huge fan of the language and tons of other people aren't either. Maybe when they move to 3.0 they'll use a real language. But they are too scared to break backwards compatibility.

ZombieApostate
Mar 13, 2011
Sorry, I didn't read your post.

I'm too busy replying to what I wish you said

:allears:

Jerry SanDisky posted:

Can anyone recommend a good, simple build system? I've tried Premake but its missing things like post build commands.

postbuildcommands doesn't work for you?

BigRedDot
Mar 6, 2008

SAHChandler posted:

This is cmake, not c or c++. It has two types. String, and string with a semicolon, which denotes a list. I'm not a huge fan of the language and tons of other people aren't either. Maybe when they move to 3.0 they'll use a real language. But they are too scared to break backwards compatibility.

Yes, but even with cmake you don't have to scream all the time. I use lowercase in my CMakeList.txt files and it works fine.

code:
set (
    peek_tools_SRCS
    pan_tool.cpp
    select_tool.cpp
    zoom_tool.cpp
)

set (
    peek_tools_HDRS
    pan_tool.hpp
    select_tool.hpp
    tool.hpp
    zoom_tool.hpp
)

add_library (peek_tools ${peek_tools_SRCS} ${peek_tools_HDRS})

astr0man
Feb 21, 2007

hollyeo deuroga
I use lowercase for cmake operators and all caps for variables. I guess I only do it that way out of habit from writing shell/environment variables and crap, but I think it makes it slightly easier to differentiate between variables and filenames at a quick glance.

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

astr0man posted:

I use lowercase for cmake operators and all caps for variables. I guess I only do it that way out of habit from writing shell/environment variables and crap, but I think it makes it slightly easier to differentiate between variables and filenames at a quick glance.

I do this as well and it's considered "the write thing to do" by the community at this point.

Posting Principle
Dec 10, 2011

by Ralp

Not right now, because it doesn't have access to tokens. I think I may just end up using SCons.

Edit: oh my gosh scons is actually very nice

Posting Principle fucked around with this message at 01:31 on Jun 6, 2013

Valtis
Sep 21, 2009
I have this piece of code that normally works just like you'd expect:
code:

    std::ofstream file("debug.txt");

    try
    {
        file << "Throwing something..." << std::endl;
        throw std::runtime_error("Why isn't this caught?");
    }
    catch (const std::runtime_error &e)
    {
        file << "Caught runtime error: " << e.what();
        return -1;
    }
    catch(const std::exception &e)
    {
        file << "Caught generic exception:  " << e.what();
        return -1;
    }
    catch(...)
    {
        file << "Unhandled exception";
        return -1;
    }
After running this code, the debug.txt has following lines:

Throwing something...
Caught runtime error: Why isn't this caught?


However, if I include Boost/Filesystem header anywhere in my project, the exception escapes the catch blocks, debug.txt only has the first line and I get nice windows prompt telling that something went wrong with my program. Why does including the filesystem header seemingly break exception handling? I'm using MinGW 4.72 and Boost 1.52 on Windows 7.

raminasi
Jan 25, 2005

a last drink with no ice
Are there any obvious reasons that a program using static versions of some third-party libraries would be slower than the same program using shared versions of those same libraries? This is on windows, and the libraries are Boost and a Boost-like geometry library.

Cubiks
Aug 31, 2005
I wish I had something witty to put here...

GrumpyDoctor posted:

Are there any obvious reasons that a program using static versions of some third-party libraries would be slower than the same program using shared versions of those same libraries? This is on windows, and the libraries are Boost and a Boost-like geometry library.

My very rough guess would be that it's related to executable size. A statically linked, larger executable could have more cache misses, slowing the whole thing down. Same reason why setting compiler optimizations for speed before space can actually have a detrimental impact. Of course, this is all a guess, so I could be way off the mark.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

GrumpyDoctor posted:

Are there any obvious reasons that a program using static versions of some third-party libraries would be slower than the same program using shared versions of those same libraries? This is on windows, and the libraries are Boost and a Boost-like geometry library.
If by "third-party libraries" you mean libraries you didn't compile yourself: they may not actually be compiled from the same code or using the same compiler settings.

If there's some library that both the third-party library and your code uses, with the static libraries there's only one copy of that library, while with shared there may be a second (different) version statically linked into the shared library.

raminasi
Jan 25, 2005

a last drink with no ice

Cubiks posted:

My very rough guess would be that it's related to executable size. A statically linked, larger executable could have more cache misses, slowing the whole thing down. Same reason why setting compiler optimizations for speed before space can actually have a detrimental impact. Of course, this is all a guess, so I could be way off the mark.

The final binary size is the same, which I also don't understand.

shrughes
Oct 11, 2008

(call/cc call/cc)
Is everything in these libraries you use templatized?

raminasi
Jan 25, 2005

a last drink with no ice

shrughes posted:

Is everything in these libraries you use templatized?

Well not everything, or else there wouldn't be binaries. But almost everything.

Valtis
Sep 21, 2009

Valtis posted:

I have this piece of code that normally works just like you'd expect:
code:

    std::ofstream file("debug.txt");

    try
    {
        file << "Throwing something..." << std::endl;
        throw std::runtime_error("Why isn't this caught?");
    }
    catch (const std::runtime_error &e)
    {
        file << "Caught runtime error: " << e.what();
        return -1;
    }
    catch(const std::exception &e)
    {
        file << "Caught generic exception:  " << e.what();
        return -1;
    }
    catch(...)
    {
        file << "Unhandled exception";
        return -1;
    }
After running this code, the debug.txt has following lines:

Throwing something...
Caught runtime error: Why isn't this caught?


However, if I include Boost/Filesystem header anywhere in my project, the exception escapes the catch blocks, debug.txt only has the first line and I get nice windows prompt telling that something went wrong with my program. Why does including the filesystem header seemingly break exception handling? I'm using MinGW 4.72 and Boost 1.52 on Windows 7.

Found a solution to this:

This seems to be issue only if I use static linking with libgcc\libstdc++; if I remove one or both of -static-libgcc and -static-libstdc++ flags, exceptions start working again. GCC documentation on the subject does say that "There are several situations in which an application should use the shared libgcc instead of the static version. The most common of these is when the application wishes to throw and catch exceptions across different shared libraries. In that case, each of the libraries as well as the application itself should use the shared libgcc.", however I'm not throwing across libraries so I'm not sure why there is an issue here.

Slurps Mad Rips
Jan 25, 2009

Bwaltow!

Valtis posted:

Found a solution to this:

This seems to be issue only if I use static linking with libgcc\libstdc++; if I remove one or both of -static-libgcc and -static-libstdc++ flags, exceptions start working again. GCC documentation on the subject does say that "There are several situations in which an application should use the shared libgcc instead of the static version. The most common of these is when the application wishes to throw and catch exceptions across different shared libraries. In that case, each of the libraries as well as the application itself should use the shared libgcc.", however I'm not throwing across libraries so I'm not sure why there is an issue here.

Was boost.filesystem compiled with the same -static-libgcc and -static-libstdc++ flags?

Adbot
ADBOT LOVES YOU

Valtis
Sep 21, 2009

SAHChandler posted:

Was boost.filesystem compiled with the same -static-libgcc and -static-libstdc++ flags?

When I built boost I only changed the compiler it uses since it defaults to visual C++, so that is likely the issue. At least I know have some idea what caused this, I honestly thought it must have been some odd compiler bug first.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply