|
If someone were writing an emulator in C++, I can see them getting confused as to why some of the elements in their enum of opcodes were illegal or whatever, but that's kind of a stretch
|
# ? Apr 17, 2014 08:49 |
|
|
# ? Jun 8, 2024 02:32 |
|
Suspicious Dish posted:Yes. But if you have a variable named "not", you deserve to get your code broken. Not that uncommon if you're building an AST or similar, in my limited experience. (And "compl" is out of bounds too?)
|
# ? Apr 17, 2014 09:41 |
|
Subjunctive posted:Not that uncommon if you're building an AST or similar, in my limited experience. (And "compl" is out of bounds too?) Yeah, I ran into this on a school project this semester. We were making a composite class hierarchy for logical expressions, and we just named all of our classes things like "Imp", "Neg", and of course, "And" and "Or". Visual Studio didn't bat an eye, but when we finished and transferred it to the school's system and tried to compile, we got a bunch of errors about identifiers or keywords or whatever g++ wanted to say about them.
|
# ? Apr 17, 2014 12:20 |
|
Ah, yeah, I forgot about that; that's a valid use case. Just use not_ and move on.
|
# ? Apr 17, 2014 15:15 |
|
Digraphs/trigraphs/alternate tokens are the kind of thing that should have been implemented at the text editor level, not the language level.
|
# ? Apr 17, 2014 15:18 |
|
OneEightHundred posted:Digraphs/trigraphs/alternate tokens are the kind of thing that should have been implemented at the text editor level, not the language level. You're thinking about it wrong. What if your source file is stored in a character encoding which flat out doesn't have representations for those tokens? That's obviously a non-issue these days, but it was a big issue when these features were added. And the correct response of "just use a not dumb character encoding" wasn't good enough for the committee.
|
# ? Apr 17, 2014 15:55 |
|
Suspicious Dish posted:What if your source file is stored in a character encoding which flat out doesn't have representations for those tokens?
|
# ? Apr 17, 2014 18:37 |
|
( moved this from the iOS thread because I think it's more of a posix sockets issue... ) I'm having an issue sending Multicast UDP packets from an iOS device that is connected to a Wifi network without a DNS server configured. When connected to a network without DNS I get an error returned from sendto and errno = 51 : network is unreachable. I can fix the issue by setting the DNS server to any valid IP on the network ( including the IP of the iOS device itself ) even if the IP is not a DNS server but I'd rather not force my users to do that. Here's some example code which shows the issue. code:
|
# ? Apr 18, 2014 21:23 |
fankey posted:( moved this from the iOS thread because I think it's more of a posix sockets issue... ) Can you send regular UDP broadcast (i.e. destination 255.255.255.255) when the device has no configured DNS server? I'm suspecting that perhaps iOS makes an assumption that if no DNS server is configured then you simply aren't on any network and then cuts short any attempt at doing network stuff. It could be a sort of power-savings measure.
|
|
# ? Apr 18, 2014 22:11 |
|
nielsm posted:Can you send regular UDP broadcast (i.e. destination 255.255.255.255) when the device has no configured DNS server? I can receive multicast UDP, send/receive unicast UDP and make TCP/HTTP connections without any issues. The only thing that doesn't work is sending multicast UDP.
|
# ? Apr 18, 2014 22:33 |
|
fankey posted:I can receive multicast UDP, send/receive unicast UDP and make TCP/HTTP connections without any issues. The only thing that doesn't work is sending multicast UDP. Is this because Bonjour coopts multicast UDP? I remember having weird interactions between DNS and mcast UDP on OS X, but it was a long time ago. (mcast routes weren't set up until Bonjour initialized, and with broken DNS it failed, or something.) I think this is probably an Apple-related thing, but I'm not certain.
|
# ? Apr 19, 2014 14:38 |
|
So this is baby level stuff/is probably ugly code, but I'm stumped. I've been working through a C++ textbook on my own and doing the programming exercises in each chapter and am having problems with this one. The part of the code that isn't working for me is this block: for (x = 1; x <= floors; x++) { if (x != 13) { cout << "How many rooms are on floor " << x << "? "; cin >> rooms; cout << "How many rooms are occupied on floor " << x << "? "; cin >> occupied; total_occupied += occupied; total_rooms += rooms; } } Basically, this block is supposed to tally how many rooms/occupied rooms there are total across all floors of a hotel, except for the 13th floor ( the number of floors is previously defined by the user). Every time I run the program I get a wild number for total_rooms, but occupied_rooms is appropriate. For example, if I input 14 for 'floors' and enter 1 room per floor and 1 occupied room per floor the end values are: total_rooms is 52 (should be 13) total_occupied is 13 I'm sure it's something really obvious that's starting me in the face, but I can't figure out what the problem is.
|
# ? Apr 21, 2014 00:08 |
|
You are initializing total_rooms to 0, right?
|
# ? Apr 21, 2014 00:22 |
First a tip, use the code tag to mark up program code, it tends to make it easier to read and prevents smilies from accidentally taking over some sequences. You can also get it to do syntax-highlighting:pre:[code=cpp] // code goes here // (the "cpp" is for C Plus Plus) [/code] C++ code:
Either way, there's a few possible things that could be biting you. First, you should post all of your code, including your variable declarations. The types you use for the variables can be important, even if you don't think so yourself. What I think is the most likely right now, however, is that you are forgetting to initialize total_occupied and total_rooms, so instead of starting out as 0 they start out with a "random" value.
|
|
# ? Apr 21, 2014 00:23 |
|
nielsm posted:What I think is the most likely right now, however, is that you are forgetting to initialize total_occupied and total_rooms, so instead of starting out as 0 they start out with a "random" value.
|
# ? Apr 21, 2014 01:00 |
|
Wow, thanks for the quick responses. I was literally just about to copy and text the code in here and realized I had initialized the values like this:C++ code:
C++ code:
|
# ? Apr 21, 2014 01:12 |
|
Valithan posted:Also I assume the bit about having warnings on high refers to having the compiler give more warnings about possibly poorly written bits? Yep. If you post your compiler people can give you recommended warning settings.
|
# ? Apr 21, 2014 03:08 |
|
Valithan posted:And everything is working fine now. Thanks for the help! Also I assume the bit about having warnings on high refers to having the compiler give more warnings about possibly poorly written bits? I don't understand why compiler defaults aren't "crapload of warnings". I could see why for backwards compatibility they wouldn't want craploads of warnings and warnings treated as errors, but the worst thing warnings would do is sound a bit scary when you're compiling someone else's old code.
|
# ? Apr 21, 2014 04:13 |
|
I'm going to be starting a project in C++ that has to be windows/linux cross platform. I think I'm going to go with gcc on linux. Can anyone give me pros and cons for different compiler choices on windows? I guess I'm looking at gcc w/ mingw and visual studio. Also, does anyone have any good solutions for 3rd party dependencies like boost? Am I just gonna have to build everything I need because windows doesn't have package management? edit: I don't do very much windows dev so this might be a ridiculous concern but I don't want to lock myself out of using MS APIs, if that's a concern at all with the gnu toolchain. Dren fucked around with this message at 16:06 on Apr 24, 2014 |
# ? Apr 24, 2014 16:03 |
|
Generally, my best experiences have been: - use VS on Windows, because you get a debugger that work - build from the command line either with nmake or mingw-make - package everything you depend on, including the CRT redist and DirectX installer The mozilla-build package has a pile of stuff all bundled up that can help a lot; it's what Mozilla uses for the Win32 development side of Firefox and friends, and I always start with it now because I get bash and python and the paths all set up etc etc. https://wiki.mozilla.org/MozillaBuild
|
# ? Apr 24, 2014 16:30 |
|
Dren posted:I'm going to be starting a project in C++ that has to be windows/linux cross platform. I think I'm going to go with gcc on linux. Can anyone give me pros and cons for different compiler choices on windows? I guess I'm looking at gcc w/ mingw and visual studio. Also, does anyone have any good solutions for 3rd party dependencies like boost? Am I just gonna have to build everything I need because windows doesn't have package management? GCC for Linux and MinGW for Windows would work fine if you want to go the free route. With MinGW you use the native Windows APIs, it isn't Cygwin which turns Windows into a Posix like system.
|
# ? Apr 24, 2014 16:31 |
|
Subjunctive posted:Generally, my best experiences have been: Thanks, I'm thinking about using Vagrant along with Chef to configure the build environment so maybe I'll have it drop MozillaBuild on the Windows environment. Any preference for a build system? I'm thinking about looking at CMake since it will create a visual studio solution and I guess I can nmake that.
|
# ? Apr 24, 2014 16:48 |
|
Dren posted:I'm going to be starting a project in C++ that has to be windows/linux cross platform. I think I'm going to go with gcc on linux. Can anyone give me pros and cons for different compiler choices on windows? I guess I'm looking at gcc w/ mingw and visual studio. Also, does anyone have any good solutions for 3rd party dependencies like boost? Am I just gonna have to build everything I need because windows doesn't have package management? I don't program for windows, but I understand you can cross-compile from Linux to Windows with MinGW. If I were to do windows programming, this is what I would do, but that's because I prefer programming in a Linux environment.
|
# ? Apr 24, 2014 18:14 |
|
Edison was a dick posted:I don't program for windows, but I understand you can cross-compile from Linux to Windows with MinGW. In my experience this is the falsest of economies. Even if you do all your development on Linux, compile on Windows to test and distribute. Please. For the children.
|
# ? Apr 24, 2014 19:07 |
|
You can get Visual C++ Express which will let you have a really good debugger and IDE at no cost. Microsoft's C++ compiler, CL, is also available for no cost on its own if you want. Unfortunately it doesn't use the same compile flags as GCC/Clang but the documentation for it is extensive. A multi-platform build system like CMake or Premake can really help; you setup your project using their system and they spit out makefiles for pretty much any platform you like (GNU makefiles, Visual Studio project files, XCode project files, etc...). There's also nothing stopping you from using Visual C++ Express to code and debug then compile with GCC under MinGW if you want to go that route. As for CL specifically... its very fast and produces pretty good optimized code. Its not fully compliant with C++11 if you're using that but supports most of the major features aside from constexpr and variadic templates. Microsoft has their own cludgy way of doing variadic templates using huge macros that are supposed to "just work"; never tried. It supports the .Net facilities of Managed C++ if you ever want to use that and is the only way to produce "Modern Windows" applications (Metro) using C++. I don't know if the libraries provided with MinGW support some of the more modern Window's APIs like DirectX 10/11 and so forth so you'll need to see if that's an issue for you. Sauer fucked around with this message at 22:50 on Apr 24, 2014 |
# ? Apr 24, 2014 22:48 |
|
DSauer posted:As for CL specifically... its very fast and produces pretty good optimized code. Its not fully compliant with C++11 if you're using that but supports most of the major features aside from constexpr and variadic templates. Microsoft has their own cludgy way of doing variadic templates using huge macros that are supposed to "just work"; never tried. Visual C++ 2013 does support real variadic templates. C++11 support in the compiler and standard library are much improved over VS2010/2012 Support For C++11 Features (Modern C++)
|
# ? Apr 24, 2014 23:31 |
|
Is there a way to declare a union at a specific, preexisting memory address? I know how to declare one out of the blue, but what's the syntax for taking an arbitrary pointer and putting a union there? Paul MaudDib fucked around with this message at 00:41 on Apr 25, 2014 |
# ? Apr 25, 2014 00:39 |
|
Paul MaudDib posted:Is there a way to declare a union at a specific, preexisting memory address? code:
|
# ? Apr 25, 2014 01:03 |
|
Paul MaudDib posted:Is there a way to declare a union at a specific, preexisting memory address? Cast to a pointer of the union type, use memcpy, use placement new (in C++)... What you're asking is unclear, and, by most reasonable interpretations, it's going to be undefined behavior (which in this case will typically trigger a segfault and terminate your program). What are you trying to accomplish with this? Could you show us what you mean with a sample of code?
|
# ? Apr 25, 2014 01:06 |
|
Otto Skorzeny posted:
Working with __shared__ memory in CUDA. You have to allocate what you need in one big block and then slice it up yourself, and I need part of it to be a union.
|
# ? Apr 25, 2014 01:29 |
|
edit: posted too slow, not really applicable
taqueso fucked around with this message at 01:40 on Apr 25, 2014 |
# ? Apr 25, 2014 01:32 |
|
Paul MaudDib posted:Working with __shared__ memory in CUDA. You have to allocate what you need in one big block and then slice it up yourself, and I need part of it to be a union. Sounds like you want an allocator, a data structure that'll keep track of that memory for you. An arena is probably simplest. Here's a dumb example of one in C. C code:
When you ask for memory from it, it returns a pointer within the block of memory you create it with, and forever treats that memory as used. It never actually frees anything, but more complicated allocators would actually try and reuse freed memory. Here's an example of it in practice. Substitute block and sizeof(block) with whatever your memory block's address and size is. C code:
The Laplace Demon fucked around with this message at 12:37 on Apr 26, 2014 |
# ? Apr 25, 2014 02:41 |
|
The Laplace Demon posted:
Are return's needed for these two clauses?
|
# ? Apr 26, 2014 10:50 |
|
Kristler posted:Are return's needed for these two clauses? Yeah, NULLs or something would probably be good if you want to actually handle errors. Went ahead and threw the returns in. The Laplace Demon fucked around with this message at 13:05 on Apr 26, 2014 |
# ? Apr 26, 2014 12:34 |
|
So, to those of you accustomed to digging through crash dumps looking for leaks, I've got a question. Preface: Our allocator is build on top of Intel tbb, which I believe sits on top of VirtualAlloc. This means that when I look at our dumps in WinDbg, our allocations live in <unknown> memory regions, not in heaps. I wrote a script to walk all of the <unknown> memory regions looking for vftables, and I'm getting some weird results. Question: So, I'm getting a very high amount of vftable hits from classes that are pure virtual. I'm not sure how this is possible when pure virtual classes can't be instantiated. I have a suspicion. There are a few classes that derive from the pure virtual base that seem to not have virtual dtors. I'm wondering if we are deleting instances of these derived classes via base class pointers and leaking them. Aside from that, I can't think of what would cause this many hits for pure virtual vftable points to exist in a dump. Thoughts?
|
# ? Apr 27, 2014 19:21 |
|
I think CMake is a great tool, but I thought it was pretty difficult to learn. There are a bunch of crappy tutorials you can find via Google that describe how to throw together a trivial project, but anything more and you're basically on your own. The official CMake documentation is basically just a reference manual that fine if you just need a refresher on the syntax for doing something you already know CMake can do, but there are no examples or even general explanations for how to do common things. I guess my point is CMake has a steep learning curve if you want to do anything useful with it, mostly because of a lack of good resources not because the system itself is all that complicated. So don't get discouraged! If you're doing anything cross-platform, it's pretty great and definitely worth learning.
|
# ? Apr 27, 2014 21:08 |
|
Namen posted:So, I'm getting a very high amount of vftable hits from classes that are pure virtual. I'm not sure how this is possible when pure virtual classes can't be instantiated. Dynamic types are weird during construction and destruction. Essentially, when you're in the constructor or destructor for a base class B, all the polymorphic features behave as if B were the most-derived type. That's true even if B is abstract; calling a method that's pure virtual in B during B's construction/destruction just causes a runtime failure. The easiest way to implement that is to basically overwrite all of B's v-table pointers with the correct tables for B at the start of its constructor (after any of its base classes have been constructed) and destructor (as the very first thing). This gets really complicated when you have virtual base classes, and MSVC's solution is just hilariously space-inefficient and yet still broken. Anyway, the net result is that v-table pointers in deallocated objects pretty much always point to the v-tables for the root class. It actually works out pretty well as a way to catch use-after-free errors.
|
# ? Apr 28, 2014 01:09 |
|
rjmccall posted:Anyway, the net result is that v-table pointers in deallocated objects pretty much always point to the v-tables for the root class. It actually works out pretty well as a way to catch use-after-free errors. But should these deallocated objects still show up in the dump? I suppose it's possible that our allocator just marks the memory as free and reusable and isn't explicitly memsetting zeros or some other pattern over old data, which could in theory lead to false positives here. That sort of goes along with your statement about catching use-after-free errors, as calling methods on these pointers would throw pure virtual exceptions.
|
# ? Apr 28, 2014 02:09 |
|
Most allocators don't overwrite freed memory by default, no; it's a lot of extra cycles and bus traffic for no real purpose except to catch bugs earlier.
|
# ? Apr 28, 2014 02:44 |
|
|
# ? Jun 8, 2024 02:32 |
|
It'd be useful and cheap to NULL out the vtable pointer, though.
|
# ? Apr 28, 2014 03:06 |