|
You don't get the JIT debugger with Visual C++ Express, IIRC
|
# ? Oct 14, 2008 19:46 |
|
|
# ? Apr 29, 2024 12:41 |
|
Avenging Dentist posted:I don't see why you'd run in debug mode unless you have breakpoints set. Running without debug (Ctrl+F5) will keep the command prompt open, and if you compiled in debug mode, the JIT debugger will load up if something goes haywire anyway. Because most people who have never programmed before don't know the difference? After all, it's the exact problem the person who asked the question was having. Anyway, Ctrl+F5 works here as well, but if you're writing an *interactive* console app a cin.get() to pause the app is not exactly verboten.
|
# ? Oct 15, 2008 07:59 |
|
Avenging Dentist posted:I don't see why you'd run in debug mode unless you have breakpoints set. Running without debug (Ctrl+F5) will keep the command prompt open, and if you compiled in debug mode, the JIT debugger will load up if something goes haywire anyway.
|
# ? Oct 15, 2008 22:41 |
|
Hi, I would like to create a CComboBox using MFC, where the EditBox part of the CComboBox remains a constant size, while the font size of the drop down box (ComboLBox?) is larger than that of the editbox, which would change the overall size of the drop down box. Now I think the only way to do this is to create an "Owner draw" Combo box, as I have been through a few example of Font List Combo boxes from various sources. However, when I try to implement any "owner draw" box in my own case, I get Debug Assertion Errors, as all the examples I have seen create the combo box in the resource view (using the IDE) and I don't want to do this, I want to create the combobox in the program code. I have tried many time to create my own class which inherits from CComboBox, then try and perform myOwnComboBox->Create(...) methods, but to no avail. Mainly because I really don't understand what is required of an owner drawn box. But I have read through alot of documentation online, but none of it its much help. SO can anyone suggest any directions to take? (using Visual Studio C++ 2008 btw) Cheers!
|
# ? Oct 16, 2008 15:03 |
|
I've got some very simple code which generates an inexplicable error if I compile it using GCC in Linux, but Visual Studio 2005 compiles it with no problems. Here is the code, and the error I'm getting: code:
Is there some standard that I'm breaking here, which VS just happens to allow while GCC is more strict? If so, how can I work around this? If it were only the most recent version of GCC then I'd suspect a compiler bug, but with two different major versions giving the same results, that seems unlikely.
|
# ? Oct 17, 2008 00:09 |
|
You need the "typename" keyword before before the third declaration because list<_Elem>::iterator is dependent upon your template parameter. Without saying "typename" there's actually no guarantee that list<_Elem>::iterator is a type at all. Some jerk could have made a specialized version of list where iterator is a member variable, or doesn't even exist.
|
# ? Oct 17, 2008 00:13 |
|
That worked, thanks!
|
# ? Oct 17, 2008 00:29 |
|
Ok, I feel retarded. Shouldn't something like: code:
|
# ? Oct 17, 2008 10:03 |
|
Mod is a terrible way to get rands in a specific range. You'll pretty much always wind up with the range being biased to certain values. Instead, get your rand into the range 0 to 1(i.e. (double)rand()/RAND_MAX), then multiply that to get a number in your range.
|
# ? Oct 17, 2008 10:24 |
|
TheSleeper posted:Mod is a terrible way to get rands in a specific range. You'll pretty much always wind up with the range being biased to certain values. Technically speaking, this doesn't remove the bias, just evenly distributes it among the elements. This might be great if you're doing damage rolls in a roleplaying game, but if you're trying to simulate selecting one out of N items, this isn't any better than the modulus approach. If you want a completely unbiased random number generator it's a bit trickier to pull off My feeling is that there are very few situations where "mod" is too inaccurate but "double and divide" is accurate enough. That said: yes, the original code will generate a range from 80 inclusive to 120 exclusive, assuming your rand() isn't ridiculously broken. (Did you remember to seed it?)
|
# ? Oct 17, 2008 10:30 |
|
ZorbaTHut posted:Technically speaking, this doesn't remove the bias, just evenly distributes it among the elements. This might be great if you're doing damage rolls in a roleplaying game, but if you're trying to simulate selecting one out of N items, this isn't any better than the modulus approach. If you want a completely unbiased random number generator it's a bit trickier to pull off Uh, exactly how can a bias be evenly distributed? Isn't that the opposite of bias?
|
# ? Oct 17, 2008 11:02 |
|
rand is usually typed to return an int, and C doesn't require a particular semantics for the % operator when applied to negative dividends. Many platforms use modulus semantics, i.e. (x/y,x%y)=(a,b) where 0<=b<y and ay+b=x, but it's also permitted to use remainder semantics, i.e. |ay|<=|x| and -y<b<y. If you're seeing a range of 40-120, this may be why. EDIT: to be precise, C requires / and % to be consistent (i.e. (x/y)*y+x%y=x), and it requires the absolute value of x % y to be less than the absolute value of y whenever y is non-zero, and it furthermore requires x % y to be non-negative whenever x is, but that's it. rjmccall fucked around with this message at 12:24 on Oct 17, 2008 |
# ? Oct 17, 2008 12:10 |
|
rand is also guaranteed to return a non-negative int. What are you getting at?
|
# ? Oct 17, 2008 12:36 |
|
TheSleeper posted:Uh, exactly how can a bias be evenly distributed? Isn't that the opposite of bias?
|
# ? Oct 17, 2008 14:04 |
|
Vanadium posted:rand is also guaranteed to return a non-negative int. What are you getting at? So it is, my mistake.
|
# ? Oct 17, 2008 22:29 |
|
What's MSVC's equivalent to gcc's "attribute (constructor)"? (Makes a function run at program startup, before main()).
|
# ? Oct 17, 2008 23:53 |
|
UraniumAnchor posted:What's MSVC's equivalent to gcc's "attribute (constructor)"? (Makes a function run at program startup, before main()). If you're using DLLs, there's _DLL_InitTerm
|
# ? Oct 17, 2008 23:56 |
|
Just put it in the constructor of a global object
|
# ? Oct 18, 2008 00:42 |
|
TheSleeper posted:Uh, exactly how can a bias be evenly distributed? Isn't that the opposite of bias? let's pretend rand_max is 13 and we need a number from 0-9 (double)rand() / RAND_MAX * 10 will be any of the following values 0/13 = 0.0 = 0 10/13 = 0.77 = 0 20/13 = 1.53 = 1 30/13 = 2.31 = 2 40/13 = 3.07 = 3 50/13 = 3.84 = 3 60/13 = 4.62 = 4 70/13 = 5.38 = 5 80/13 = 6.15 = 6 90/13 = 6.92 = 6 100/13 = 7.69 = 7 110/13 = 8.46 = 8 120/13 = 9.23 = 9 130/13 = 10.0 = 10 See the bias? It biases towards 0, 3 and 6. They are twice as likely as any other number. edit: I feel the need to point out that this bias decreases as RAND_MAX gets larger. But it's still there! Atom fucked around with this message at 00:57 on Oct 18, 2008 |
# ? Oct 18, 2008 00:54 |
|
Accidentally posted this in the general questions, so here we go again: In C: quote:char c = 148; Rather than outputting 148, it gives me -108. On closer inspection, I seem to be getting incorrect values when an ASCII character's integer value is => 100. Is something wrong with my libraries, or am I retarded/missing something?
|
# ? Oct 18, 2008 02:25 |
|
quote:Rather than outputting 148, it gives me -108. On closer inspection, I seem to be getting incorrect values when an ASCII character's integer value is => 100.
|
# ? Oct 18, 2008 02:52 |
|
citsejam posted:Accidentally posted this in the general questions, so here we go again: char is probably stored as a signed 8 bit integer. -108 is the 2's complement of 148 in 8 bits. dis astranagant fucked around with this message at 03:56 on Oct 18, 2008 |
# ? Oct 18, 2008 02:52 |
|
I've got an assignment to write a C/C++ program that produces a COM file that will output "Hello World" when ran. However I have no idea how to make a program that produces a COM file. The only advice I got way that a COM file is just a memory image, and that I can use all the DOS APIs I want. I tried googling but I have a feeling I am googling the wrong thing.
|
# ? Oct 18, 2008 03:49 |
|
Cross_ posted:%i, as the letter implies, is expecting an int. You are feeding it a char, that leaves printf with taking "random" values from nearby memory to fill in the missing 3 bytes. This is completely wrong.
|
# ? Oct 18, 2008 07:20 |
|
citsejam posted:Rather than outputting 148, it gives me -108. On closer inspection, I seem to be getting incorrect values when an ASCII character's integer value is => 100. Is something wrong with my libraries, or am I retarded/missing something? Your system uses signed characters, meaning "char" values may hold integers from -128 to 127. 148 falls outside this range, so it's interpreted as negative according to 2's compliment. You want something like this: code:
|
# ? Oct 18, 2008 07:51 |
|
http://forums.somethingawful.com/showthread.php?threadid=2779598&pagenumber=29#post350837583 Ok, guys, can we please stop talking about this. Also, for the curious, varargs like in printf promote integral values to ints and floating point values to doubles. (Sometimes this is a lie; I'm pretty sure IA64 promotes integral values to longs).
|
# ? Oct 18, 2008 07:52 |
|
Is it possible to forward declare derived child classes? I would think no, but it seems to make taking full advantage of covariant return types pretty difficult if your base classes are dependent on one another. foobase.h code:
code:
fooderived.h code:
code:
|
# ? Oct 20, 2008 06:19 |
|
Why would you think that class FooDerived; is bad? It's 100% legal.
|
# ? Oct 20, 2008 06:30 |
|
Avenging Dentist posted:Why would you think that class FooDerived; is bad? It's 100% legal. Forward declaring FooDerived is just fine, but the problem is that as far as I can tell any notions of lineage require definition, not just declaration, so it can't be used to redefine FooBase * BarBase::returnFoo(FooBase * _foo) as FooDerived * BarDerived::returnFoo(FooBase * _foo)
|
# ? Oct 20, 2008 06:33 |
|
Ah, I see what you mean by "covariant return types". Those are strictly illegal in C++ (as well they should be, since they open up a can of worms with respect to overloading). That's just not how C++ works; apparently it's legal in Java, but I honestly don't see the point anyway.
|
# ? Oct 20, 2008 06:40 |
|
Avenging Dentist posted:Ah, I see what you mean by "covariant return types". Those are strictly illegal in C++ (as well they should be, since they open up a can of worms with respect to overloading). That's just not how C++ works; apparently it's legal in Java, but I honestly don't see the point anyway. They're legal in C++ according to the spec though apparently it was a long time before MSVC/GCC supported them. I can see the can of worms they open, but on the other hand they can also enforce some safety too. They were intended to reduce the need for dynamic_cast-ing, but they don't really. I figured I would be fancy and use them, but that's why I was surprised since they are apparently way less useful than they were intended (and Bjorn says as much in "Design and Evolution of C++", but I hadn't had occasion to try them out until now. I figured I must be doing it wrong, so that's seriously a bummer imo
|
# ? Oct 20, 2008 06:45 |
|
I got it working, if you care. Here's the trick:code:
This might not even be strictly valid C++, I only tested it in MSVC 8. If you want all the source files, I'll send them to you, but the above is the relevant bit. EDIT: I managed to make it appear transparent to the user but it's all just memory allocation tricks so it's nothing special. Avenging Dentist fucked around with this message at 08:06 on Oct 20, 2008 |
# ? Oct 20, 2008 07:34 |
|
Avenging Dentist posted:I got it working, if you care. Here's the trick: Yeah, I'm pretty sure that's not valid, but it's quite a hack, seriously that's clever
|
# ? Oct 20, 2008 08:10 |
|
Thug Bonnet posted:Yeah, I'm pretty sure that's not valid, but it's quite a hack, seriously that's clever Well, it compiles without warning in MSVC and GCC with -Wall -pedantic. The trick really is just that wrapper<T,Base> asserts that T is a subclass of Base (except in the case where Base = nil, obviously), and then wraps up the necessary cast into the class.
|
# ? Oct 20, 2008 08:28 |
|
Why is it that when having a diamond form (which of course one should avoid to begin with) a cast demands an in between cast to tell which of the class branches you take? It seems unnecessary since I end up with the same no matter if I use (class4*)(class3*) or (class4*)(class2*).code:
|
# ? Oct 22, 2008 14:00 |
|
Jarl posted:I end up with the same no matter if I use (class4*)(class3*) or (class4*)(class2*). You do not. code:
Edit: http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.8 Vanadium fucked around with this message at 14:13 on Oct 22, 2008 |
# ? Oct 22, 2008 14:08 |
|
Thank you, that was very help full.
|
# ? Oct 22, 2008 15:16 |
|
Is there a good C++ based open-source unzip library? I just need to extract a bunch of files from a zip to a given location. zlib doesn't appear to handle zip files directly and minizip is lacking documentation and looks more complicated than I need. Ideally I just want to call Unzip( sourceZip, destinationPath ). Oh, it needs be Win32 compatible as well.
|
# ? Oct 22, 2008 16:33 |
|
Minizip takes like 10 lines of code to unzip something, just use that.
|
# ? Oct 22, 2008 18:50 |
|
|
# ? Apr 29, 2024 12:41 |
|
I'm having a hard time understanding how malloc'd memory is freed: I understand you can free it explicitly with free(), but I've seen contradicting information as to whether a malloc'd piece of memory that's being pointed to is freed when the program terminates. So, do I have to call free() for everything, or just in case I want to change the pointer that points to the malloc'd memory?
|
# ? Oct 23, 2008 03:28 |