|
EDIT: Solved.
FamDav fucked around with this message at 06:31 on Jul 26, 2012 |
# ? Jul 26, 2012 04:44 |
|
|
# ? Jun 8, 2024 07:30 |
|
rjmccall posted:Critically, that type cannot be copyable, or you'll immediately lose your const correctness; instead, you have to make instances of some other shared pointer type from it. Sean Parent has given some awesome talks on value semantics, including how all types are inherently regular (which includes copyability). Poor quality video on a talk from this year: https://www.youtube.com/watch?v=_BpMYeUFXv8
|
# ? Jul 26, 2012 06:11 |
|
That was very interesting. Over the last few years I've been finding myself leaning towards creating only 'regular' types without trying to be clever about copying or shared ownership, particularly since I got r-value references. However sometimes sharing seems unavoidable. For example, if I load a texture off disk, I don't want to have to reload it or copy it due to limited memory. But if two unrelated parts of a game happen to require the same texture, I need to share that texture object. It seems a perfect case for shared pointers (in fact I have yet another 'smart pointer' called Resource<T> which manages IO in addition to the ref counting paraphernalia). I'm happy with how all that works, unless someone has a better idea than shared ownership - I'm still having a think about the copy-on-write stuff from that talk. A texture is of course perfectly copyable and I do allow that using regular copy semantics, if that's what you really want to do. But all I'm trying to achieve with the const-propogation part is a solution to this simple situation: code:
|
# ? Jul 26, 2012 12:04 |
|
I have been somewhat out of the loop regarding C++ changes for the past 5 years or so (doing Java & Obj-C stuff). What is a good book that covers the C++ 11 and TR1 changes ?
|
# ? Jul 27, 2012 03:36 |
|
Cross_ posted:I have been somewhat out of the loop regarding C++ changes for the past 5 years or so (doing Java & Obj-C stuff). What is a good book that covers the C++ 11 and TR1 changes ? The Wikipedia entry.
|
# ? Jul 27, 2012 06:16 |
|
Has anyone been messing with Visual Studio 2012 Express RC? I'm trying to find out if they removed the Memory and Thread windows. They documented them as unavailable in Visual C++ 2010, but you could still access them with Expert Settings enabled. The likelihood of that being a mistake combined with their supposed original plan to drop C++ support from Express entirely has me wondering if they'll still be there next round.
|
# ? Jul 30, 2012 21:40 |
|
I have Visual Studio 2010 that I use for mostly C# stuff, but there is one C project I work with that I would like to move into Visual Studio IDE for easier code navigation. This project is currently built using a batch file, that calls out to some special gcc versions that target an embedded device. What I'm wondering is if there is a way to just specify my own entire build process in VS2010 to just use this batch file or something similar? I see that you can add build steps before/after the built in ones, but I think I want to replace the built-in build steps all together.
|
# ? Jul 30, 2012 22:59 |
peepsalot posted:What I'm wondering is if there is a way to just specify my own entire build process in VS2010 to just use this batch file or something similar? I see that you can add build steps before/after the built in ones, but I think I want to replace the built-in build steps all together. Create a "Makefile Project" instead of a "Win32 Project". I don't really know where to go from there, but it's how you'd get started. I'm not sure if much of the fancy features will work if you aren't using Microsoft's toolset.
|
|
# ? Jul 30, 2012 23:10 |
|
I'm trying to get a working setup of llvm+clang using libc++ headers for compiling a library (libpqxx) using c++11. I'd try to take this question to a mailing list but I'm not even sure which mailing list would be the right one to go to in this case (llvm? clang? libc++? libpqxx?) because I have no idea if I even have things set up properly. I'm on OS X Lion. This is what I've done: Edit: I can't figure out how to get the forums to not insert [url] tags... Bash code:
Bash code:
Bash code:
Now on to libpqxx: Bash code:
code:
strconv.cxx:195:10: error: assigning to 'bool' from incompatible type 'std::__1::basic_istream<char>' which I fixed by casting the expression to bool before the assignment. Then finally I tried to compile and got an error that I can't figure out coming from a libc++ header: code:
$HOME/.clang+llvm+libc++/build/Release+Asserts/bin/clang++ -DHAVE_CONFIG_H -I. -I../include/pqxx -I../include -I../include -I/usr/include -std=c++11 -nostdinc++ -I$HOME/.clang+llvm+libc++/llvm/projects/libcxx/include -MT rmlo.o -MD -MP -MF .deps/rmlo.Tpo -c -o rmlo.o rmlo.cxx At this point I'm not sure what to do. Shouldn't min() be in the std namespace? Please help! Lexical Unit fucked around with this message at 22:16 on Aug 2, 2012 |
# ? Aug 2, 2012 22:13 |
|
I'm running OSX, what is a good IDE for C++? I tried using Eclipse, but I can't get anything to work, not even the sample Hello World program...
|
# ? Aug 2, 2012 22:53 |
|
Pollyanna posted:I'm running OSX, what is a good IDE for C++? I tried using Eclipse, but I can't get anything to work, not even the sample Hello World program...
|
# ? Aug 2, 2012 22:57 |
|
Lexical Unit posted:Sublime Text 2 is amazing and has completely replaced vim for me. You can even use this plugin to get auto complete suggestions using clang++ Apparently it needs 10.6.8 to run and I have no idea where to find a copy of Snow Leopard God, I miss Windows.
|
# ? Aug 2, 2012 23:12 |
|
Pollyanna posted:Apparently it needs 10.6.8 to run and I have no idea where to find a copy of Snow Leopard God, I miss Windows.
|
# ? Aug 2, 2012 23:15 |
|
Volte posted:It works on Lion and Mountain Lion too I have 10.5.8. This has been a problem for a long time and my computer is dying anyway. I'm considering getting a new one.
|
# ? Aug 2, 2012 23:20 |
|
Lexical Unit posted:At this point I'm not sure what to do. Shouldn't min() be in the std namespace? Please help! Your include stack suggests that there are headers in pqxx which are hijacking libc++'s includes. If you can't remove those, you might try using -isystem for the libc++ path.
|
# ? Aug 3, 2012 00:29 |
|
rjmccall posted:Your include stack suggests that there are headers in pqxx which are hijacking libc++'s includes. If you can't remove those, you might try using -isystem for the libc++ path. I was able to get the library to compile though, I just had to delete <pqxx/tuple> (which all it did was include <pqxx/tuple.hxx>) and replace the lines where it was included with tuple.hxx instead.
|
# ? Aug 3, 2012 02:24 |
|
The man page is terrible; it's a known bug that we have definite plans to address. I really shouldn't have been surprised that -isystem didn't help, though. Headers are terrible.
|
# ? Aug 3, 2012 04:13 |
|
Pollyanna posted:I'm running OSX, what is a good IDE for C++? I tried using Eclipse, but I can't get anything to work, not even the sample Hello World program... I've been using the Eclipse CDT for years on Linux and I'm about to give up. Every new release seems to break existing features in imaginative ways and there's just no hope in trying to debug it. Google searching leads me to believe that Netbeans is a decent alternative so give that a shot.
|
# ? Aug 5, 2012 01:30 |
|
Goodness gracious Netbeans and Eclipse are not C++ IDEs do not use them for C++, you would be more productive in EDIT.COM
|
# ? Aug 5, 2012 03:50 |
|
OneEightHundred posted:Has anyone been messing with Visual Studio 2012 Express RC? They're there in the default settings.
|
# ? Aug 6, 2012 07:19 |
|
Otto Skorzeny posted:Goodness gracious Netbeans and Eclipse are not C++ IDEs do not use them for C++, you would be more productive in EDIT.COM I guess I just imagined the last 4 years of the Eclipse CDT's existence then.
|
# ? Aug 6, 2012 14:48 |
|
eXXon posted:I guess I just imagined the last 4 years of the Eclipse CDT's existence then. I found it really hard to believe that both Netbeans and Eclipse made IDEs that supported C++ until I googled it myself. Why god why did the world need more [probably, I have no idea and no urge to find out] lovely C++ IDEs?
|
# ? Aug 6, 2012 15:27 |
|
hieronymus posted:I found it really hard to believe that both Netbeans and Eclipse made IDEs that supported C++ until I googled it myself. Why god why did the world need more [probably, I have no idea and no urge to find out] lovely C++ IDEs? The cross-platform aspect of it can be nice sometimes. I teach a C++ programming course from time to time to non-CS majors, many of whom have never done any programming before. (Don't get me started on why C++ is a terrible language for this, I teach what I'm assigned.) Since these students can barely do anything more with a computer than Facebook, I'm certainly not going to teach them "make" or anything remotely close to the terminal. Using Netbeans or Eclipse at least means I only have to write one set of instructions for both Windows and Mac users. Both IDEs have their bumpy parts, but it works well enough.
|
# ? Aug 6, 2012 15:53 |
|
Netbeans and Eclipse are probably the best C++ IDEs other than Visual Studio. Eclipse CDT has been around for at least 10 years and Netbeans has supported C++ for 4-5 years also. Personally I prefer just using a nice text editor but if you really need IDE features, there's nothing wrong with Netbeans or Eclipse.
|
# ? Aug 6, 2012 22:06 |
|
How does CodeBlocks compare to NetBeans / Eclipse and vice-versa? I've used the MS tools and I've used CodeBlocks on a linux machine very briefly but I've not used NetBeans or Eclipse.
|
# ? Aug 6, 2012 22:20 |
|
Crankit posted:How does CodeBlocks compare to NetBeans / Eclipse and vice-versa? Well I like CodeBlocks over Eclipse. NetBeans can make proper Makefiles though if you're lazy, CodeBlocks needs a plugin to do so.
|
# ? Aug 6, 2012 22:48 |
|
So I noticed something odd while trying to fix a bug today, using Android NDK r8b (GCC 4.6.x):code:
code:
|
# ? Aug 7, 2012 00:41 |
|
Isn't BOOL only a char in Win32 whilst _Bool is an int for everyone else?
|
# ? Aug 7, 2012 01:48 |
|
It could be, but that really has no bearing here, does it? I'm only using it to modify the memory contents of the bool in question. The underlying issue here is that both b and !b are non-zero in this situation, which broke some if statements that were expecting that property to hold. The compiler here is merely flipping the lowest bit, rather than setting a non-zero "bool" to zero. I suspect that's not correct behavior, but I'm not sure. I worked around it anyway because the REAL issue was uninitialized memory, but this particular bit of code doesn't have that problem and still acts in an "unexpected" way.
|
# ? Aug 7, 2012 02:04 |
|
I think it's correct behavior, assuming this is C++, and not some typedef. bool's are permitted to behave as neither true nor false if you don't use them in a proper, well-defined, typesafe way (the standard gives an example of an uninitialized bool); and this is clearly doing weird stuff since there is nothing that says that true and false have to be represented in a certain way (in particular, sizeof(bool) need not be 1); merely that they convert to and from ints in a certain way.
|
# ? Aug 7, 2012 02:14 |
|
Yeah, that's what I suspected but wasn't sure. Thanks.
|
# ? Aug 7, 2012 02:19 |
|
UraniumAnchor posted:So I noticed something odd while trying to fix a bug today, using Android NDK r8b (GCC 4.6.x): Undefined behavior -- not only can it behave in the weird way you observed, but it can poison your entire program, and do something completely ridiculous. It's a violation of strict aliasing. This has more information: http://dbp-consulting.com/StrictAliasing.pdf Edit: I think I'm wrong here, actually. C99 says that any type can be safely accessed through char*, and C++11 says basically the same. I'm not sure what the deal is with bool, though. schnarf fucked around with this message at 03:58 on Aug 7, 2012 |
# ? Aug 7, 2012 03:52 |
|
schnarf posted:Undefined behavior -- not only can it behave in the weird way you observed, but it can poison your entire program, and do something completely ridiculous. It's a violation of strict aliasing. This has more information: http://dbp-consulting.com/StrictAliasing.pdf Your initial claim was correct. Yes, you are able to cast and access through char*, but all bets are off once you write via a char and then try to read back as a bool. That is undefined. It is, however, valid to write to the memory via the char*, then write to the memory with the bool, and then read through it via the bool.
|
# ? Aug 7, 2012 04:03 |
|
That Turkey Story posted:Your initial claim was correct. Yes, you are able to cast and access through char*, but all bets are off once you write via a char and then try to read back as a bool. That is undefined. It is, however, valid to write to the memory via the char*, then write to the memory with the bool, and then read through it via the bool. What if you write to the memory with the bool, then read with the char*, then write that char value back through the char*, then read with the bool?
|
# ? Aug 7, 2012 04:51 |
|
char* is allowed to alias any other type, so that wouldn't be the issue. It's just the compiler making (perfectly legal) assumptions about the possible values of bool, and only ever looking at the least significant bit as a result. This is a good example of why you should never use bool (or _Bool, or any kind of enum) in a wire format because the other end can't be trusted.
|
# ? Aug 7, 2012 04:59 |
|
shrughes posted:What if you write to the memory with the bool, then read with the char*, then write that char value back through the char*, then read with the bool? Yeah, that's fine for pods as long as you're copying the same amount of memory (again, a sizeof( bool ) might not be the same as sizeof( char )). I think the actual requirements are more general than that but I'm too lazy to check -- probably just that the type has a trivial copy constructor and a trivial destructor but don't quote me on that. I'm sure someone here knows offhand I.E. rjmccall. E: or maybe just trivial copy assignment That Turkey Story fucked around with this message at 05:15 on Aug 7, 2012 |
# ? Aug 7, 2012 05:12 |
|
I've got barely any knowledge of c++ so this is probably a dumb question, but... I've been trying to get some linux c++ code to compile on osx under the xcode 4.4 llvm compiler. I've found out how to make it compile, but I'm not sure exactly why it was complaining in the first place. A stripped-down version of the code: code:
If I change the "Foo & other" to be a reference-to-const "Foo const& other", it compiles fine. From what I've read it's best to have this in a copy constructor anyway, but this isn't my code. But I don't know why the copy constructor matters for the line code:
Could anyone describe exactly what the compiler does then, or some section in the spec that says? Thanks.
|
# ? Aug 8, 2012 02:20 |
|
Foo(12) creates a temporary Foo and under C++'s rules non const references don't match temporaries. MSVC has an extension to C++ that lets non const references take temporaries but I'm not sure what's going on in linux.
|
# ? Aug 8, 2012 02:33 |
|
clang doesn't warn with -std=c++11 and the warning specifically mentions C++98, so maybe the standard changed? edit: The clang docs for -Wbind-to-temporary-copy specifically says this changed from C++98 to C++11.
|
# ? Aug 8, 2012 02:39 |
|
|
# ? Jun 8, 2024 07:30 |
|
That Turkey Story posted:Yeah, that's fine for pods as long as you're copying the same amount of memory (again, a sizeof( bool ) might not be the same as sizeof( char )). I think the actual requirements are more general than that but I'm too lazy to check -- probably just that the type has a trivial copy constructor and a trivial destructor but don't quote me on that. I'm sure someone here knows offhand I.E. rjmccall. It's [basic.types]p2. You can copy an object into a char array or into another object, but the objects have to be the same (dynamic) type, that type has to be "trivially copyable", and the objects have to be complete objects (i.e. not base class sub-objects). Of course, you also can't violate aliasing rules while you're at it. So you can use a char* to write into a bool object, but if the value you're writing there didn't come from a (validly initialized) bool object, you're breaking the rules. There's also some language about object vs. value representation, with the intent that you can construct object representations which are not legal value representations, but then using a value loaded from that object has undefined behavior. IIRC, this part is clearer in the C standard. "Trivially copyable" means (1) trivial destructor, (2) no non-trivial copy or move constructors, and (3) no non-trivial copy or move assignment operators.
|
# ? Aug 8, 2012 03:03 |