|
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.
|
# ? Jun 2, 2013 18:02 |
|
|
# ? Jun 8, 2024 06:44 |
|
It turns out I'd forgotten a semicolon after the } at the end of my class definition.
|
# ? Jun 2, 2013 19:18 |
|
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?
|
# ? Jun 2, 2013 19:33 |
|
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)
|
# ? Jun 2, 2013 19:55 |
|
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?
|
# ? Jun 3, 2013 00:10 |
|
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? 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:
code:
|
# ? Jun 3, 2013 00:26 |
|
Volte posted:Here's a C grammar: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html#declaration Also, typedef is a storage class, so you can do int typedef foo;
|
# ? Jun 3, 2013 00:40 |
|
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.
|
# ? Jun 3, 2013 08:37 |
|
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.
|
# ? Jun 3, 2013 10:55 |
|
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 |
# ? Jun 3, 2013 12:02 |
|
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
|
# ? Jun 4, 2013 18:31 |
|
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. 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 |
# ? Jun 4, 2013 18:37 |
|
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. 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
|
# ? Jun 4, 2013 18:38 |
|
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.
|
# ? Jun 4, 2013 19:02 |
|
Can anyone recommend a good, simple build system? I've tried Premake but its missing things like post build commands.
|
# ? Jun 4, 2013 19:12 |
|
Jerry SanDisky posted:Can anyone recommend a good, simple build system? I've tried Premake but its missing things like post build commands. cmake
|
# ? Jun 4, 2013 19:22 |
|
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 |
# ? Jun 4, 2013 19:31 |
|
You only need one CMakeLists.txt per project.
|
# ? Jun 4, 2013 19:38 |
|
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.
|
# ? Jun 4, 2013 20:49 |
|
xgalaxy posted:I was a big fan of premake but development is slow. 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)
|
# ? Jun 4, 2013 22:03 |
|
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.
|
# ? Jun 4, 2013 23:32 |
|
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:
|
# ? Jun 5, 2013 00:43 |
|
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.
|
# ? Jun 5, 2013 02:33 |
|
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). 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.
|
# ? Jun 5, 2013 03:07 |
|
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.
|
# ? Jun 5, 2013 06:05 |
|
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?
|
# ? Jun 5, 2013 08:16 |
|
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:
|
# ? Jun 5, 2013 13:46 |
|
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.
|
# ? Jun 5, 2013 13:57 |
|
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.
|
# ? Jun 5, 2013 14:36 |
|
ZombieApostate posted:postbuildcommands doesn't work for you? 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 |
# ? Jun 5, 2013 14:37 |
|
I have this piece of code that normally works just like you'd expect:code:
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.
|
# ? Jun 5, 2013 17:13 |
|
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.
|
# ? Jun 5, 2013 20:58 |
|
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.
|
# ? Jun 5, 2013 21:11 |
|
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 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.
|
# ? Jun 5, 2013 21:16 |
|
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.
|
# ? Jun 5, 2013 21:16 |
|
Is everything in these libraries you use templatized?
|
# ? Jun 5, 2013 21:26 |
|
shrughes posted:Is everything in these libraries you use templatized? Well not everything, or else there wouldn't be binaries. But almost everything.
|
# ? Jun 5, 2013 23:07 |
|
Valtis posted:I have this piece of code that normally works just like you'd expect: 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.
|
# ? Jun 6, 2013 22:27 |
|
Valtis posted:Found a solution to this: Was boost.filesystem compiled with the same -static-libgcc and -static-libstdc++ flags?
|
# ? Jun 6, 2013 22:47 |
|
|
# ? Jun 8, 2024 06:44 |
|
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.
|
# ? Jun 6, 2013 22:55 |