|
What the heck is going on here. I have a makefile like this: code:
g++ -std=c++0x -Wall -o Game *.cpp -lncurses everything works as expected. I'm doing a Linux port of a thing I've had working in Windows for a long time. I haven't been working with raw makefiles like this in forever but this just seems weird
|
# ? Jan 14, 2015 20:27 |
|
|
# ? May 21, 2024 18:24 |
|
You can delete all those rules, since make has implicit rules by default. Just keep LIBS, CFLAGS, and do:code:
|
# ? Jan 14, 2015 22:55 |
|
Suspicious Dish posted:You can delete all those rules, since make has implicit rules by default. Just keep LIBS, CFLAGS, and do: Hmm OK. Anyway, my original problem went away with a later version of GCC. I guess it might've been a compiler bug
|
# ? Jan 15, 2015 11:47 |
|
netcat posted:Hmm OK. Anyway, my original problem went away with a later version of GCC. I guess it might've been a compiler bug It's never a compiler bug.
|
# ? Jan 15, 2015 18:53 |
|
fritz posted:It's never a compiler bug. but god, when it is, does it take a long time to find out
|
# ? Jan 15, 2015 18:55 |
|
Times it is a compiler bug:
|
# ? Jan 15, 2015 19:50 |
|
Suspicious Dish posted:Times it is a compiler bug:
|
# ? Jan 15, 2015 20:11 |
|
Okay, I have a C++ RTTI conundrum. I need to test whether class A is a subclass of class B without having instances of either class lying around (so I can't just dynamic_cast).
|
# ? Jan 15, 2015 22:28 |
|
Schmerm posted:Okay, I have a C++ RTTI conundrum. I need to test whether class A is a subclass of class B without having instances of either class lying around (so I can't just dynamic_cast). This seems unrelated to RTTI, since you can get what you need using entirely static information. You could probably just use is_convertible to check whether an instance of A would be implicitly convertible to an instance of B, without actually needing to have an instance on hand.
|
# ? Jan 15, 2015 23:31 |
|
I once ran across a compiler bug in a random number generator, that caused my program to crash. That was a fun one tracking down.
|
# ? Jan 16, 2015 00:14 |
|
Don't forget STL/libc bugs, which aren't technically part of the compiler, but might as well be. The major containers (list/vector/deque/map) and most common functions in <algorithm> are usually bug-free, but the rest is hit and miss, for both GCC/Clang and MSVC. Especially for C++11 content. Right now, both compilers' implementations of <functional> are basically garbage. <type_traits> was garbage until recently as well, because both compilers relied on internal hooks to implement things like is_convertible, and didn't always get it right.
|
# ? Jan 16, 2015 00:29 |
|
What's wrong with functional?
|
# ? Jan 16, 2015 00:40 |
|
Jabor posted:This seems unrelated to RTTI, since you can get what you need using entirely static information. You could probably just use is_convertible to check whether an instance of A would be implicitly convertible to an instance of B, without actually needing to have an instance on hand. Cool! All these type query utility thingies are pretty useful. Unfortunately, I can't use is_convertible in my case I'm creating a facility to register a C++ class and bind it with some scripting language stuff. Each time I register a class, I want to scan through all the already-registered classes and see if the incoming class is a subclass of any of them, and use that information to update the ordering/relationship of the registered classes. There's dynamic behaviour in there.
|
# ? Jan 16, 2015 00:45 |
|
Schmerm posted:Each time I register a class, I want to scan through all the already-registered classes and see if the incoming class is a subclass of any of them, and use that information to update the ordering/relationship of the registered classes. It seems incredibly silly to me, but std::type_info (what I would have used) does not support this e: not with the standard std::type_info at least, of loving course this information is available to the runtime environment for exception handling e2: do you have any code to show us? hackbunny fucked around with this message at 01:09 on Jan 16, 2015 |
# ? Jan 16, 2015 01:06 |
|
You're asking for reflection, and C++ doesn't support that.
|
# ? Jan 16, 2015 02:16 |
|
Schmerm posted:Cool! All these type query utility thingies are pretty useful. Unfortunately, I can't use is_convertible in my case I'm creating a facility to register a C++ class and bind it with some scripting language stuff. Each time I register a class, I want to scan through all the already-registered classes and see if the incoming class is a subclass of any of them, and use that information to update the ordering/relationship of the registered classes. There's dynamic behaviour in there. This sounds like runtime reflection, honestly. Most of typeinfo won't help you (it's mostly compiletime operations), and there's nothing in C++ RTTI (or Boost::TypeIndex) that can support this -- you can identify what class a pointer is, and distinguish classes using typeid::hash_code, but you can't determine inheritance. You're going to have to implement this yourself.
|
# ? Jan 16, 2015 02:36 |
|
On the plus side, there's a couple reflection proposals for C++17 so in a couple years you might have access to them (or a decade or so if you're using MSVC).
|
# ? Jan 16, 2015 15:06 |
|
Schmerm posted:Cool! All these type query utility thingies are pretty useful. Unfortunately, I can't use is_convertible in my case I'm creating a facility to register a C++ class and bind it with some scripting language stuff. Each time I register a class, I want to scan through all the already-registered classes and see if the incoming class is a subclass of any of them, and use that information to update the ordering/relationship of the registered classes. There's dynamic behaviour in there. How are you having this work, exactly? What is the facility to register a C++ class and bind it with some scripting language stuff? Is it a C++ program? A program in the scripting language? A C++ module for a scripting language program? What is the scripting language? You said you want to scan through already registered classes for inheritance relationships upon registering a class. How is a class registered? Does registering a class happen at C++ runtime or via scanning the source or what? The whole idea of registering a C++ class you know nothing about and don't have an instance of is weird to me. If you don't know what it is you can't call any methods on it or use it in any way. If you don't have an instance of it then you've got to be scanning the source, right? Because where else would you even get a class to register?
|
# ? Jan 17, 2015 03:36 |
Dren posted:You said you want to scan through already registered classes for inheritance relationships upon registering a class. How is a class registered? Does registering a class happen at C++ runtime or via scanning the source or what? I imagine it's some template stuff. A factory class that takes a worker class as template parameter, and you then make globally initialized instances of those templates factories that register themselves. C++ code:
nielsm fucked around with this message at 11:57 on Jan 17, 2015 |
|
# ? Jan 17, 2015 11:55 |
|
If the classes are determined at compile time, as they would be with templates, a code inspection tool could be used to work out the inheritance relationships then poop out a Config file or something that has them all. Something like ctags or doxygen.
|
# ? Jan 17, 2015 19:51 |
Dren posted:If the classes are determined at compile time, as they would be with templates, a code inspection tool could be used to work out the inheritance relationships then poop out a Config file or something that has them all. Something like ctags or doxygen. Yep the only way to have a (polymorphic) runtime object in C++ that represents a class rather than being an instance of that class, is to have a factory similar to that. And since you're already bothering with making your own reflection-like thing there you may as well also bake in some extra metadata. If you e.g. need some kind of ordering on the classes registered with that kind of factory, you could do it by having an additional, optional parameter to the factory instance constructor and to the factory base registration function, that takes the registered name of the base class the registered class inherits from. It's not automatic, by any means, but it can work. You could also try to bake the information into the classes being registered, with some static members of some sort, and reference those in the factory classes. (I suppose you could theoretically also try to get a pointer to the vtable of a class and work with that directly, but then you're getting into implementation-defined territory and definitely won't be portable.)
|
|
# ? Jan 17, 2015 20:03 |
|
Getting a vtable pointer is always going to involve undefined behavior. The unportable but still valid solution would be to look up the layout of class type_info objects on your platform(s), redeclare that in your own code, and using that to dynamically query the bases of the class. If you're using gcc/clang, you can just steal the declarations from libc++abi's private headers; they should work regardless of what C++ library you're actually using, because the layout is dictated by the ABI. (Don't call the extra virtual functions unless you're sure you're using libc++abi, though.)
|
# ? Jan 18, 2015 11:24 |
|
glibmm does this through horrible hacks to register subtypes with the GType type system. You can steal their magic if you want.
|
# ? Jan 18, 2015 19:16 |
|
I create Lua bindings for C++ classes. Each class must be explicitly registered with a function call that looks something like:code:
When register_class() is called, it adds a new entry to a list of registered classes. Each entry is a structure that looks like this: code:
check_instance is a function, which given an Object at runtime, will tell you whether or not that Object is of a class derived from the registered class. The actual lambda assigned to check_instance is: code:
1) The C++ function has an instance of something, but hidden behind a base-class Object* pointer. 2) The list of RTTIEntries is scanned, and each entry's check_instance() is called on the Object* pointer. 3) The first entry that returns true is selected as the Lua class that correspods to the Object*'s actual run-time type. 4) Hooray, that entry's lua_name can now be used to tell Lua what class the returned handle is going to be. --- What's missing from this system is a way to order the list of RTTIEntries such that if there exist several registered C++ classes that are related to each other, the most-derived classes come first, since they will be encountered first on the linear search in step 3). This is why, during register_class, I'd love to be able to examine the RTTIEntry list and find a smart place to insert the new entry, based on class relationships, without having any instance of anything lying around.
|
# ? Jan 20, 2015 05:40 |
|
Schmerm posted:What's missing from this system is a way to order the list of RTTIEntries such that if there exist several registered C++ classes that are related to each other, the most-derived classes come first, since they will be encountered first on the linear search in step 3). This is why, during register_class, I'd love to be able to examine the RTTIEntry list and find a smart place to insert the new entry, based on class relationships, without having any instance of anything lying around. There's a couple of ways to go about this. Here's a sort of naive approach, where you call your existing is_instance methods on an instance of the new type when you add it to the registry. C++ code:
C++ code:
The Laplace Demon fucked around with this message at 08:59 on Jan 20, 2015 |
# ? Jan 20, 2015 08:50 |
|
The Laplace Demon posted:
sweet mother of satan! Yep, I think that'll do. edit: I also didn't know that a standard C-like function pointer can point to a lambda, and thought only std::function could do that edit2: this will gently caress with the debugger when it's set to break-on-throw, but filtering should fix that Schmerm fucked around with this message at 19:28 on Jan 20, 2015 |
# ? Jan 20, 2015 19:18 |
|
C++ lambdas that don't capture are just function pointers. (C++ lambdas that do capture are their own unique anonymous struct type with an operator(), which is why you need std::function in the first place.)
|
# ? Jan 20, 2015 19:32 |
|
pseudorandom name posted:C++ lambdas that don't capture are just function pointers. No, they're still anonymous (empty) struct types with an operator(); they just also have a conversion operator to function-pointer type.
|
# ? Jan 20, 2015 19:35 |
|
I'm a C++ beginner, trying to learn the language and messing around with Qt currently. I just did one of the tutorials where you make a sample program with widgets. It works fine and all, but there's a part of the code I'm not understanding. textfinder.h: code:
code:
|
# ? Jan 20, 2015 20:06 |
|
Ui::TextFinder and its setupUi() method are defined in ui_textfinder.h, which is generated at build time from the corresponding .ui file (and then included from textfinder.cpp, whereas in textfinder.h you only need the forward declaration).
|
# ? Jan 20, 2015 20:12 |
|
daft punk railroad posted:Ui::TextFinder and its setupUi() method are defined in ui_textfinder.h, which is generated at build time from the corresponding .ui file (and then included from textfinder.cpp, whereas in textfinder.h you only need the forward declaration). Ah ok thank you. I figured something like that was going on
|
# ? Jan 20, 2015 21:00 |
|
I'm looking to drop a real simple webserver into a windows application - it only has to respond to GET requests and will have to serve a page that it generates from some of its own internal state. Any suggestions for something ready made?
|
# ? Jan 23, 2015 00:51 |
|
Newf posted:I'm looking to drop a real simple webserver into a windows application - it only has to respond to GET requests and will have to serve a page that it generates from some of its own internal state. Microsoft has made an open source C++ REST SDK that may be able to help: https://casablanca.codeplex.com/
|
# ? Jan 23, 2015 14:38 |
|
Volguus posted:Microsoft has made an open source C++ REST SDK that may be able to help: https://casablanca.codeplex.com/ A good find, but unfortunately requires a more modern runtime than what I have available.
|
# ? Jan 23, 2015 16:34 |
|
Newf posted:I'm looking to drop a real simple webserver into a windows application - it only has to respond to GET requests and will have to serve a page that it generates from some of its own internal state. Boost ASIO comes with a web server example that's pretty easy to integrate in other projects.
|
# ? Jan 23, 2015 20:01 |
I have a Cmake/linking question. I set up a project to use GLM, GLFW and SOIL, and while GLFW and GLM come with Cmake files and are compiled with my project, which I assume means the relevant parts of the library are compiled into my executable and it will work when I try to run it on a system that doesn't have these libraries installed. SOIL, however, doesn't come with a Cmake file, and I have to link the library file and include files through my CmakeList. If I took my application and ran it on a system that doesn't have libSOIL.a in the particular path I do, would it then still work? These are the lines where I'm defining/linking SOIL in my CMakeList.txt:code:
|
|
# ? Jan 24, 2015 13:14 |
|
Joda posted:If I took my application and ran it on a system that doesn't have libSOIL.a in the particular path I do, would it then still work? Edit: vvvv Funny, I did almost say "except silly license agreement cases". roomforthetuna fucked around with this message at 07:36 on Jan 27, 2015 |
# ? Jan 24, 2015 19:39 |
|
roomforthetuna posted:You should never need to distribute a .lib or .a file with a binary. I've heard of an edge case to this rule, where you use a LGPL component and need to provide a static binary. Using shared objects and dynamic linked binaries is the easiest way to satisfy the LGPL, but you can also do it by providing intermediate objects (.o files) and static libraries (.a files), since the LGPL grants the freedom to replace the library with a bugfixed version.
|
# ? Jan 26, 2015 10:30 |
|
I guess that works if your main program was only a single object file. But that would be pretty stupid if you had a ton of object files. It is simpler to just use dynamic linking.
|
# ? Jan 26, 2015 17:32 |
|
|
# ? May 21, 2024 18:24 |
|
It's been a while since I used filestreams, and I'm having a problem I haven't encountered before. I'm trying to create an input filestream from a plain text file, but apparently the failbit for the stream is getting set to true. Here's my code:C++ code:
|
# ? Jan 27, 2015 03:04 |