|
I hate macros and try to avoid them if at all possible, but I'm torn here. I made a Signal class:code:
code:
code:
code:
|
# ? Jul 13, 2013 19:31 |
|
|
# ? May 26, 2024 20:08 |
|
Seven Round Things posted:I hate macros and try to avoid them if at all possible, but I'm torn here. I made a Signal class: Is writing void really that bad? Using your macro name is no fewer characters. I'd personally just get used to it. If you really want a macro, the only potential concern I can think of is that you should be fully qualifying in the macro (in other words, start the type with :: in the off-chance that someone is invoking the macro from a namespace that has its own "handy"). Really though, you should just use a template alias for this instead of a macro, assuming your compiler supports them: code:
|
# ? Jul 13, 2013 19:54 |
|
^^ edit: fb. In c++11 you can declare your handy signal like this: code:
code:
Other than that, your macro solution can theoretically cause namespace scoping problems, but its probably not going to happen.
|
# ? Jul 13, 2013 20:10 |
|
quote:template alias code:
That Turkey Story posted:Is writing void really that bad? Using your macro name is no fewer characters. I'd personally just get used to it. I think I'll just use the void() syntax after all, it does also make it clearer that the functions to be attached to it must return void... thanks!
|
# ? Jul 13, 2013 20:33 |
|
Seven Round Things posted:I suppose it's not. To be honest, the main reason I'm hesitant is because someone else seeing HANDY_SIGNAL won't immediately know that it is just a wrapper for declaring a Signal- they'll think it's a trigger for a bunch of difficult-to-understand preprocessor wizardry.
|
# ? Jul 13, 2013 20:53 |
|
I'm curious now - I haven't seen a construct of that form before (the Signal<void(int x,int y)> thing). How would you use something like this, and for what? I see they're being used to referencing onClick behaviors or something, is the idea to have your input-triggered functions able to be in a list of some sort on an object? What would a simple usage of the class look like?
|
# ? Jul 13, 2013 20:59 |
|
roomforthetuna posted:I'm curious now - I haven't seen a construct of that form before (the Signal<void(int x,int y)> thing). How would you use something like this, and for what? I see they're being used to referencing onClick behaviors or something, is the idea to have your input-triggered functions able to be in a list of some sort on an object? What would a simple usage of the class look like? Take a look at std::function for a similar example of that syntax.
|
# ? Jul 13, 2013 21:24 |
|
roomforthetuna posted:How would you use something like this, and for what? I see they're being used to referencing onClick behaviors or something, is the idea to have your input-triggered functions able to be in a list of some sort on an object? What would a simple usage of the class look like? code:
code:
code:
I can disconnect a function when I no longer want it to receive events by saving the ID and passing it to disconnect(): code:
code:
code:
In a GUI system, for example, you might connect many functions to a Button's onClicked. In a game engine, you might have onMouseClicked, onMouseMoved, onKeyReleased, onJoystickButtonPressed, etc. Again this isn't a new idea, there are many such systems including boost::signals2 and nano-signal-slot. I'm quite happy with mine, though, and making it was educational. Seven Round Things fucked around with this message at 21:31 on Jul 13, 2013 |
# ? Jul 13, 2013 21:27 |
|
Seven Round Things posted:[use of his signal] And thanks Jerry SanDisky too, for the link explaining the syntax of declaring such a thing. Looks like I should bone up on my C++11 a bit!
|
# ? Jul 13, 2013 21:50 |
|
I'm trying to create a simple Camera object...code:
code:
I've never worked with handles before. Is a handle actually a CHAR or something?
|
# ? Jul 16, 2013 03:16 |
|
No. Your "code here to return handle" is wrong, most likely. Try posting your actual code so we have a chance to identify the problem.
|
# ? Jul 16, 2013 03:18 |
|
I haven't put it in yet, but am using it elsewhere. It's part of an api for the camera... it's just code:
|
# ? Jul 16, 2013 03:27 |
|
bobua posted:
Maybe try initializing the char array with "" rather than 0.
|
# ? Jul 16, 2013 03:35 |
|
roomforthetuna posted:You're trying to initialize a char array with just 0. My guess is the next entry, handle1, is trying to fill in the second character of that char array. This appears to be the right track, I commented out the device id and sn and it stopped complaining about the handle. Thanks.
|
# ? Jul 16, 2013 03:44 |
|
The struct definition, in the eyes of the first initializer, is equivalent to:C++ code:
|
# ? Jul 16, 2013 05:15 |
|
I'm going to be moving from a mainly C++ job to something else, but would like to keep up with C++. What's the landscape look like for open source C++ projects that need contributors?
|
# ? Jul 19, 2013 03:17 |
|
Jerry SanDisky posted:I'm going to be moving from a mainly C++ job to something else, but would like to keep up with C++. What's the landscape look like for open source C++ projects that need contributors? There's always KDE, though the way they use Qt and kdelib might make it too much of a niche if you want to keep up with c++ in general.
|
# ? Jul 19, 2013 10:25 |
|
Jerry SanDisky posted:I'm going to be moving from a mainly C++ job to something else, but would like to keep up with C++. What's the landscape look like for open source C++ projects that need contributors? FWIW Apache Traffic Server (proxy server) is c++
|
# ? Jul 19, 2013 14:19 |
|
GCC, LLVM, Clang, LLDB, Chromium, Boost should be pretty obvious large C++ projects. Some of the NoSQL projects should be in C++. Some of the messaging fabrics are: QPID, 0mq.
|
# ? Jul 19, 2013 15:28 |
|
DO NOT VOLUNTARILY WORK WITH THE GCC CODEBASE
|
# ? Jul 19, 2013 15:51 |
|
We used to have a fork of stdlibc++ and that scared me off GNU code forever. Mozilla and Boost look most promising.
|
# ? Jul 19, 2013 17:24 |
|
Otto Skorzeny posted:DO NOT VOLUNTARILY WORK WITH THE GCC CODEBASE A coworker, David Malcolm, used to be a core Python developer, and he got switched over to the gcc/tools team. His first project was to turn gcc into a better library, so he wrote a simple analysis pass that detected wherever code used global state, and recompiled gcc with it. The log file was 12MB. Here's his plan for removing global state from GCC. I wish him the best of luck at not going insane.
|
# ? Jul 19, 2013 21:33 |
|
That is epic and awesome. I also wish the best of luck and skill to him.
|
# ? Jul 19, 2013 21:59 |
|
His singleton optimization is extremely clever, and he's planning on making it an optimization that's externally usable by other projects as well. He's a smart engineer.
|
# ? Jul 19, 2013 22:21 |
|
I got back to coding lately and was looking for a way to write 'global classes' without resorting to something like a singleton. I ended up abusing the static keyword to make classes that look like this (some kind of mouse wrapper):code:
It works but since this is C++ I know there's a problem with the approach. Is my use of global functionality abusive? Is this creating a bunch of copies of _pos? Is there a better way to access single-instance classes? Pontificating Ass fucked around with this message at 00:44 on Jul 20, 2013 |
# ? Jul 20, 2013 00:41 |
|
Sintax posted:It works but since this is C++ I know there's a problem with the approach. Is my use of global functionality abusive? Is this creating a bunch of copies of _pos? Is there a better way to access single-instance classes? The static local function variable code:
|
# ? Jul 20, 2013 00:55 |
|
SAHChandler posted:The static local function variable Just a heads up, this is not thread safe unless you have a compiler that properly implements the C++11 memory model.
|
# ? Jul 20, 2013 01:02 |
|
Sintax posted:I got back to coding lately and was looking for a way to write 'global classes' without resorting to something like a singleton. I ended up abusing the static keyword to make classes that look like this (some kind of mouse wrapper): I mean it's not necessarily wrong but you're really just recreating namespace functionality in a different way. The mouse position in this particular example is essentially a global variable and you should regard it as such. (For something like a mouse position that is likely totally fine, just don't make the mistake thinking putting things in static accessor functions magically makes them not global variables) seiken fucked around with this message at 12:59 on Jul 20, 2013 |
# ? Jul 20, 2013 12:57 |
seiken posted:I mean it's not necessarily wrong but you're really just recreating namespace functionality in a different way. The mouse position in this particular example is essentially a global variable and you should regard it as such. (For something like a mouse position that is likely totally fine, just don't make the mistake thinking putting things in static accessor functions magically makes them not global variables) And then sometimes there is more than one mouse. And sometimes you don't have one at all. (Like tablets with touch.) I'm sure it's fine for the purpose of showing variations over the singleton pattern, but in reality you may need to treat "the mouse position" differently. For instance, you may want to store historical mouse states in some way and pass those around, "2 seconds ago the mouse was at that position and the left button was held down" and such.
|
|
# ? Jul 20, 2013 13:53 |
|
nielsm posted:And then sometimes there is more than one mouse. And sometimes you don't have one at all. (Like tablets with touch.) I detest singletons and avoid them like the plague. I end up passing a lot of parameters around. Even things which seem like they are physically 'singletons' such as hardware resources often turn out not to be later.
|
# ? Jul 20, 2013 15:09 |
|
Jerry SanDisky posted:Just a heads up, this is not thread safe unless you have a compiler that properly implements the C++11 memory model. GCC has had thread safe static local construction since before C++11.
|
# ? Jul 20, 2013 18:17 |
|
pseudorandom name posted:GCC has had thread safe static local construction since before C++11. Kind of. It used a global shared mutex for local static initializations, meaning it was still easy to deadlock. They've fixed this now, but it was broken and non portable for a long time.
|
# ? Jul 20, 2013 18:38 |
|
Microsoft's C++ compiler just confused the poo poo out of me. I was debugging a really simple programming, and getting frustrated because the code was so simple, and it wasn't behaving properly. The root of the problem was, the values of one of my variables just wasn't changing as I was stepping through in the debugger: code:
code:
http://msdn.microsoft.com/en-us/library/vstudio/b80153d8.aspx MSDN posted:The C++ standard says that a variable declared in a for loop shall go out of scope after the for loop ends... So why does microsoft's c++ compiler not comply to the standard by default? Even assuming they had a good reason to do this, why am I allowed to redeclare 'i' in a scope where its already declared without my compiler giving me an error? And on top of all that, why does that suddenly make the increment and assignment operators take no effect? All of this with no indication of the compiler, jeez. Dog Jones fucked around with this message at 21:08 on Jul 20, 2013 |
# ? Jul 20, 2013 20:53 |
|
/Zc:forScope is the default...
|
# ? Jul 20, 2013 22:33 |
|
Rottbott posted:/Zc:forScope is the default... Alright, now I'm really confused. I used all default settings (like I said, this is a small project). I looked at my options and in fact /Zc:forScope is specified. So now I have no idea why the program is behaving like this. edit: To be precise, here is the behavior. code:
Dog Jones fucked around with this message at 23:47 on Jul 20, 2013 |
# ? Jul 20, 2013 23:14 |
|
Visual c++ is older than the standard and its legacy behavior is that loop init declarations survive the loop. Depending on what you have edited out of your example, you might be seeing the effects of unused value elimination.
|
# ? Jul 20, 2013 23:20 |
It looks more likely to me that it's just the debugger that's confused by the name collision, but you probably really do have two separate variables. If this is a debug (non-optimised) build, the compiled probably allocates separate slots on the stack for each "i" but the debugger doesn't follow scope properly and keeps inspecting the location for the loop-counter even when it's actually out of scope. Have you tried adding regular code to somehow output the variables, that doesn't rely on debugger inspection?
|
|
# ? Jul 20, 2013 23:31 |
|
Dog Jones posted:Alright, now I'm really confused. I used all default settings (like I said, this is a small project). I looked at my options and in fact /Zc:forScope is specified. So now I have no idea why the program is behaving like this. I tried reproducing this. I get the wrong values (i == 7) in the VC2012 debugger, which presumably is looking at the wrong part of the stack, but the program behaves as expected when run and the scoping rules are enforced by MSVC. C++ code:
|
# ? Jul 20, 2013 23:33 |
|
Xerophyte posted:I tried reproducing this. I get the wrong values (i == 7) in the VC2012 debugger, which presumably is looking at the wrong part of the stack, but the program behaves as expected when run and the scoping rules are enforced by MSVC. C++ code:
roomforthetuna fucked around with this message at 00:57 on Jul 21, 2013 |
# ? Jul 20, 2013 23:39 |
|
|
# ? May 26, 2024 20:08 |
|
I tried a test similiar to Xerophyte, and got the same results, so nielsm is probably right. roomforthetuna posted:I'm curious whether the debugger would get it right if the outer-scope declaration of i was made before the for loop, like so. The debugger still gets it wrong with this program.
|
# ? Jul 20, 2013 23:52 |