|
Ugg boots posted:We talked a couple of days ago, you mentioned that you lost your job and seemed pretty bummed about it. Nothing a week of video games won't fix though, right? Whoever you are you're gay as hell!
|
# ? Apr 4, 2009 20:35 |
|
|
# ? Apr 29, 2024 18:16 |
|
If it helps, they're (probably) going to extend the lower-price early registration fee for Boostcon until a week before it starts.
|
# ? Apr 4, 2009 20:39 |
|
What is the simple, clean way to read in either a float or int from stdin in C? >5 oh an int! (5) >5.3 a float! (5.3) >blah not a float or int! code:
|
# ? Apr 6, 2009 04:10 |
|
You're going to have to be a lot more specific. Is 1.23E2 a float or an int?
|
# ? Apr 6, 2009 04:13 |
|
#.#[E#] / nan / inf is a float # is an int anything else falls through.
|
# ? Apr 6, 2009 04:17 |
|
Probably an overcomplicated and long-winded method but... Read a string. Check for a decimal point, E etc. Use boost::lexical_cast to get the string into the required format. (int or float)
|
# ? Apr 6, 2009 04:37 |
|
Zakalwe posted:Use boost::lexical_cast to get the string into the required format. (int or float) Contero posted:in C? (P.S. http://codepad.org/l9GkajTc)
|
# ? Apr 6, 2009 05:09 |
|
Zakalwe posted:Probably an overcomplicated and long-winded method but... Avenging Dentist posted:Or meet somewhere in the middle: search the string for a decimal or an E, and then use sscanf's return value to determine valid input.
|
# ? Apr 6, 2009 05:22 |
|
I tried to come up with a way to use scanf's return value for this but I am seriously at a loss there. And I did not even think of strtol.
|
# ? Apr 6, 2009 05:27 |
|
Vanadium posted:I tried to come up with a way to use scanf's return value for this but I am seriously at a loss there. And I did not even think of strtol. scanf requires you to specify the input's type in the format string. There is no way to use scanf to detect the type of the input, only whether or not an input is matched.
|
# ? Apr 6, 2009 05:40 |
|
Yeah, the plan was kind of to try reading it as both integer and floating-point type, but since scanf only returns the amount of items matched and not the amount of bytes consumed, that was not of any use at all. welp.
|
# ? Apr 6, 2009 05:44 |
|
Avenging Dentist posted:
strtol we meet again! (thanks)
|
# ? Apr 6, 2009 06:57 |
|
I had pretty much the exact same code AD posted but whenever I tried to print out the value of the double it would come out as garbage. Finally, including stdlib.h fixed the issue. I'm not very versed in straight C, what's the reason for this? Fake edit: I should have turned on all warnings. gcc posted:warning: implicit declaration of function ‘strtol’
|
# ? Apr 6, 2009 17:36 |
|
Lexical Unit posted:How is this only a warning, and not an error? Builtins are the excuse iirc
|
# ? Apr 6, 2009 17:37 |
|
Lexical Unit posted:I had pretty much the exact same code AD posted but whenever I tried to print out the value of the double it would come out as garbage. Finally, including stdlib.h fixed the issue. I'm not very versed in straight C, what's the reason for this? C specifies what happens when you call a function with no declaration; essentially, it's as if you were calling a function declared int (*)(...). Now, first off, doubles generally get returned in totally different registers from ints, but even if they didn't, the logical operation here as far as C is concerned is to take an int value from somewhere (in this case, probably trash) and transform it to a double. Lexical Unit posted:Fake edit: I should have turned on all warnings. Foolishness.
|
# ? Apr 6, 2009 17:46 |
|
rjmccall posted:Foolishness.
|
# ? Apr 6, 2009 17:52 |
|
Mustach posted:Yes, so foolish that it was made an error in C99. test.c: In function âmainâ: test.c:17: warning: implicit declaration of function âstrtolâ test.c:19: warning: implicit declaration of function âstrtodâ code:
|
# ? Apr 6, 2009 21:03 |
|
$ gcc -x c++ -o test{,.c} test.c: In function ‘int main()’: test.c:17: error: ‘strtol’ was not declared in this scope test.c:19: error: ‘strtod’ was not declared in this scope
|
# ? Apr 6, 2009 21:05 |
|
gcc is not a stardards-conforming compiler by any stretch of the imagination, Contrero Also try it with -std=c99 -pedantic
|
# ? Apr 6, 2009 21:08 |
|
Contero posted:http://gcc.gnu.org/c99status.html posted:remove implicit function declaration - Done
|
# ? Apr 6, 2009 21:53 |
|
I'm working on UVa Problem 103 right now, and I need a little help. I've got everything working except the function which finds out which boxes fit into each other. The problem is with the solution I came up with, the UVa Judge tells me "Wrong Answer." I think part of my problem is that I'm just coming up with unnecessarily complex solutions. This is an outline of the logic I came up with. This function is being sent a box which is sorted according to the sum of their elements: Click here for the full 1260x297 image. Could someone pitch me a simpler idea, or tell me what's wrong with mine? Cosmopolitan fucked around with this message at 01:00 on Apr 7, 2009 |
# ? Apr 7, 2009 00:19 |
|
Anunnaki posted:Could someone pitch me a simpler idea, or tell me what's wrong with mine? That you're trying to express it with a flowchart. Why don't you explain your idea with something more readable, like actual code? Edit: Heck, even pseudocode!
|
# ? Apr 7, 2009 02:51 |
|
Anunnaki posted:Could someone pitch me a simpler idea, or tell me what's wrong with mine? Wow flowcharts really *are* useless for anything except the most trivial of algorithms. If you rewrite it as pseudocode I'm sure it'll be easier to see if you did anything wrong.
|
# ? Apr 7, 2009 02:51 |
|
Mustach posted:Don't ask me. Anyhow, it says so in paragraph 5 of the standard's Foreward. I was sincerely confused, not being a jackass. It's hard to tell the difference in CoC I guess.
|
# ? Apr 7, 2009 03:07 |
|
Does anyone have any suggestions for good books or tutorials on test driven development and unit testing with C++? I'm starting a new project and I'd like to give TDD a try. Google's top results look pretty good, but some of that material is out of date and isn't very in-depth and there's a lot of .Net results in there.
Mr.Radar fucked around with this message at 03:27 on Apr 7, 2009 |
# ? Apr 7, 2009 03:09 |
|
I found the Boost TDD tutorial thing really helpful in general, you might take a look.
|
# ? Apr 7, 2009 05:17 |
|
Contero posted:I was sincerely confused, not being a jackass. It's hard to tell the difference in CoC I guess.
|
# ? Apr 7, 2009 15:41 |
|
code:
|
# ? Apr 7, 2009 17:31 |
|
ultra-inquisitor posted:Why does sizeof(Foo) give me 12? Is there some odd padding going on, or is there something in the member functions which might be taking up space? If any of them are virtual, or if you have a virtual base class (which I mention only for completion, since you obviously don't), yes. Other than that, what platform are you compiling on?
|
# ? Apr 7, 2009 17:41 |
|
ultra-inquisitor posted:Why does sizeof(Foo) give me 12? Is there some odd padding going on, or is there something in the member functions which might be taking up space? Virtual members take up space because a function pointer needs to be passed around. I'm not aware of any architectures that need floats aligned on 8-byte boundaries instead of 4-, but I wouldn't be shocked if there were some.
|
# ? Apr 7, 2009 17:42 |
|
ShoulderDaemon posted:Virtual members take up space because a function pointer needs to be passed around.
|
# ? Apr 7, 2009 18:00 |
|
ultra-inquisitor posted:This'll be it. Isn't it a pointer to the vtable, though? As far as I know, compilers are free to implement vtables as either separate structures or inline with objects - if there's only a single virtual method, storing it inline saves an indirection, for example.
|
# ? Apr 7, 2009 18:06 |
|
ultra-inquisitor posted:This'll be it. Isn't it a pointer to the vtable, though?
|
# ? Apr 7, 2009 18:10 |
|
Standish posted:Are you on 64 bits?
|
# ? Apr 7, 2009 18:15 |
|
ultra-inquisitor posted:
|
# ? Apr 7, 2009 19:29 |
|
schnarf posted:I'm betting the union isn't 4 bytes as you'd expect. How much you willing to bet? It will be the vtable, as has already been covered.
|
# ? Apr 7, 2009 19:58 |
Is there any way to get the compiler to pretend that two enum types are one and the same? The situation I want is something like this:code:
|
|
# ? Apr 8, 2009 06:16 |
|
No, that would be awful and violate the basic principle of enums (that they are a specific list of possible values).
|
# ? Apr 8, 2009 06:30 |
Avenging Dentist posted:No, that would be awful and violate the basic principle of enums (that they are a specific list of possible values). It's not my choice of how to do things, it's the way the Source engine works.
|
|
# ? Apr 8, 2009 06:38 |
|
|
# ? Apr 29, 2024 18:16 |
|
huge sesh posted:It's not my choice of how to do things, it's the way the Source engine works. I doubt that the Source engine dictates that you use a language feature that does not exist.
|
# ? Apr 8, 2009 07:00 |