|
Though 4(x) obviously needs to be changed to (4*x). e:f;b ... and by like an hour, man I need to stop replying to tabs that have been open so long
|
# ? May 5, 2008 17:19 |
|
|
# ? May 18, 2024 03:54 |
|
ColdPie posted:Just kind of at a first glance (about to run out the door to school myself), this looks all right. I'd add in a check to make sure x isn't negative -- that'd create an infinite loop. Or just code:
|
# ? May 5, 2008 17:45 |
|
Paniolo posted:Here's a tutorial for writing a small Scheme interpreter in Scheme. I think it would be straightforward to take most of the concepts and re-implement them in C++. This was very helpful, thank you. Our team has decided that we're going to use structs rather than classes, so we've entered the realm of C now.
|
# ? May 5, 2008 17:58 |
|
Being aware that invoking reinterpret_cast is something that should be done with extreme care in good C++ code, I was wondering if there is anything wrong with this, or if there is a better way to do this:code:
|
# ? May 5, 2008 22:03 |
|
Since this is C++ code, why doesn't LongPacket just inherit from Packet so you can use static_cast?
|
# ? May 5, 2008 22:35 |
|
JoeNotCharles posted:Since this is C++ code, why doesn't LongPacket just inherit from Packet so you can use static_cast? I considered that, but - and I guess this should have been an alternate question - I couldn't find any definitive answer on whether or not that would preserve field ordering and packing. Since it's a network packet, it needs to be bit-for-bit accurate. So, if I write: code:
|
# ? May 5, 2008 22:47 |
|
JoeNotCharles posted:why doesn't LongPacket just inherit from Packet Smackbilly posted:I was wondering if there is anything wrong with this Smackbilly posted:or if there is a better way to do this code:
Lexical Unit fucked around with this message at 22:51 on May 5, 2008 |
# ? May 5, 2008 22:48 |
|
I do not think the language guarantees absence of padding in any case, with or without inheritance.
|
# ? May 5, 2008 23:09 |
|
Vanadium posted:I do not think the language guarantees absence of padding in any case, with or without inheritance. In gcc/g++, the #pragma pack(1) directive guarantees the absence of padding in plain structs. However I'm looking but I can't find out if this also applies if you use a struct more like a class (for example, adding constructors, using inheritence, etc). I'm not terribly concerned about portability to other compilers at the moment, but this will have to build on gcc for several platforms, so I don't want to rely on something that might work on x86 but not on ARM.
|
# ? May 5, 2008 23:14 |
|
Classes will usually have a vtable pointer at the beginning, so you can't rely on offsets from the beginning of the class. You can rely on offsets from other members, I guess. Also, use __attribute__((packed)) if you don't care about compiler portability, otherwise you'll forget to undo the #pragma and it'll be slow.
|
# ? May 5, 2008 23:29 |
|
There's only a vtable if there is a virtual function anywhere in the inheritance tree. Using #pragma pack(1) you can be fairly sure about the run-time size of a struct. However, the correct way to do what you're trying to do is to implement a serialize/unserialize method:code:
|
# ? May 5, 2008 23:45 |
|
Paniolo posted:As a general rule you really don't want to initialize a class by memcpying into it or just casting a void pointer to a class pointer, there's just so many things that can go wrong (for example, padding, network byte order vs host byte order, corrupted or malicious data, etc.)
|
# ? May 6, 2008 00:14 |
|
If anyone could take a look at this bit of code for me I'd appreciate it: http://rafb.net/p/Xr46gD55.html Line 61 is giving me the following error: Blob.cpp:61: error: cannot convert 'color' to 'color (*)[5]' for argument '1' to 'int count_cells(color (*)[5], int, int)' And I can't seem to figure out what's wrong. The count_cells function returns the number of cells marked "abnormal" or '1' which are connected to the cell being tested. The array it's trying to read in from the file is a 5x5 grid, and I'm attempting to fill it up with the color enumeration types depending if a 1 or 0 is read (the other 2 infile variables at the beginning are the test row/column, the size of the grid and the test cell are the first 4 characters in the file). As I said before, the grid is 5x5 so once I figure out how to fix this error I'll figure out some way to make the function called on a grid of arbitrary size. In case anyone wants to see the contents of the file in question: code:
Viper2026 fucked around with this message at 05:08 on May 6, 2008 |
# ? May 6, 2008 05:04 |
|
code:
code:
code:
|
# ? May 6, 2008 05:14 |
|
Thanks for the help, but this is some crap my teacher got out of a textbook and gave us that count_cells() function along with enumeration type at the top, then was like "make it do this this and this". If I had a choice of doing it some other way I would I changed the row/col size variables to type of size_t and now it lets me create the array given the values read in from my file. However, when I try to call my function: cout << count_cells(the_grid[r_size][c_size], r_test, c_test) << "\n"; again, I'm getting this: error: cannot convert 'color' to 'color (*)[5]' for argument '1' to 'int count_cells(color (*)[5], int, int)' The code in question: code:
Viper2026 fucked around with this message at 05:56 on May 6, 2008 |
# ? May 6, 2008 05:21 |
|
TSDK posted:I think your dev environment is misconfigured. By the looks of it, either there's a mismatch in the calling convention or the long double support between your executable and the library you're linking against.
|
# ? May 6, 2008 07:58 |
|
Viper2026 posted:I changed the row/col size variables to type of size_t and now it lets me create the array given the values read in from my file. However, when I try to call my function: Go look at Paniolo's post again, particular the first code block.
|
# ? May 6, 2008 09:08 |
|
Paniolo posted:Also you can't declare an array like this: Actually you can in gcc - it's a compiler extension. (You shouldn't, though, because it makes your code non-portable.)
|
# ? May 6, 2008 15:57 |
|
Why does this assert?code:
Answer: "After reading the last available character, the extraction not only reads past the end of the input sequence; it also fails to extract the requested character. Hence, failbit is set in addition to eofbit." Lexical Unit fucked around with this message at 17:26 on May 6, 2008 |
# ? May 6, 2008 16:48 |
|
This may be silly/stupid, but is it in any way possible to do this?code:
The motivation behind this is that I'm writing a number of classes that all have several identical member functions that accept enumerated values, but the enumerated values are different for each class. I was thinking it would be handy to have a common templated base class that handled the implementation of these member functions so that I wouldn't have to duplicate the code. The other way to do this (my present solution) is to have each class call templated utility functions that are in an unrelated clsas, but in that case there is still an identical interface to the utility function in each class. Obviously one solution is to move the Things struct outside of the class, but then the namespace for the Thing values would have to be FooThings:: instead of Foo::Things:: which seems inelegant to me.
|
# ? May 6, 2008 17:23 |
|
JoeNotCharles posted:Actually you can in gcc - it's a compiler extension. (You shouldn't, though, because it makes your code non-portable.) It's legal C99, but that assumes a C99 compiler. vv That means they're not perfect (see the note), but I've never had any trouble with them in practice. Mr VacBob fucked around with this message at 20:22 on May 6, 2008 |
# ? May 6, 2008 18:50 |
|
Mr VacBob posted:It's legal C99, but that assumes a C99 compiler. IIRC variable-length arrays are one of the most problematic C99 features with respect to the implementations of various compilers edit: this page says they're still broken in gcc 4.3
|
# ? May 6, 2008 19:31 |
|
Smackbilly posted:This may be silly/stupid, but is it in any way possible to do this? Off the top of my head, try code:
|
# ? May 6, 2008 21:18 |
|
JoeNotCharles posted:Since Foo inherits FooBase, I believe you can now refer to FooBase::Things as Foo::Things. (Not in the actual definition of Foo, but at least you're containing the inelegance.) http://codepad.org/exT9EKui You actually can refer directly to Foo::Thing from within the definition of Foo. What you have to be careful with is in the Base class.. if you do something like this: code:
|
# ? May 6, 2008 22:54 |
|
What the gently caress, Qt 4.4 supports futures? Holy poo poo.
|
# ? May 7, 2008 04:48 |
|
code:
I checked the man page and its meant to be a const char* :| (actually it says char * const, but i tried that too and it didn't help) What am i missing? gcc version 4.0.1 (Apple Inc. build 5465)
|
# ? May 8, 2008 03:15 |
|
You're passing a pointer to a array of const char* to a function which takes a pointer to a const char*. Try this:code:
|
# ? May 8, 2008 03:44 |
|
Oh I see, thanks.
|
# ? May 8, 2008 04:06 |
|
Professor Science posted:What the gently caress, Qt 4.4 supports futures? Holy poo poo. I took a look for that and couldn't find any docs. Can you point me to a reference?
|
# ? May 8, 2008 04:17 |
|
JoeNotCharles posted:I took a look for that and couldn't find any docs. Can you point me to a reference? http://doc.trolltech.com/4.4/qfuture.html http://labs.trolltech.com/blogs/2007/03/08/making-asynchronous-function-calls-with-qfuture/
|
# ? May 8, 2008 15:25 |
|
Oh, I completely missed that 4.4 already had an entry on the main doc page - I was looking around for previews and getting pissed off that all the Google links were outdated. Wow, the whole QConcurrent framework looks fantastic.
|
# ? May 8, 2008 15:29 |
|
JoeNotCharles posted:Wow, the whole QConcurrent framework looks fantastic.
|
# ? May 8, 2008 21:00 |
|
code:
|
# ? May 8, 2008 22:08 |
|
Soldat posted:When I call longprim_check, I just went it to return true if the input is simply 'add1' or 'sub1'. Anything else I want it to return false. Right now it's returning true for everything. What glaringly obvious thing am I missing? The strcmp function?
|
# ? May 8, 2008 22:10 |
|
Soldat posted:When I call longprim_check, I just went it to return true if the input is simply 'add1' or 'sub1'. Anything else I want it to return false. Right now it's returning true for everything. What glaringly obvious thing am I missing? The strcmp function and the fact that most of your nested if statements do not have else cases. If you pass "adff" to primcheck_add it's just going to fall out in the middle, returning garbage (which would be interpreted as true unless it was 0). Your compiler should be warning you about this.
|
# ? May 8, 2008 22:20 |
|
code:
Soldat fucked around with this message at 23:22 on May 8, 2008 |
# ? May 8, 2008 23:02 |
|
In addition to what they say before, if you really refuse to use strcmp, have you never heard of the && operater? edit: and why are you using an array of 10 characters when you only ever use 4 in both those functions. TheSleeper fucked around with this message at 23:13 on May 8, 2008 |
# ? May 8, 2008 23:11 |
|
oops, accidental post
|
# ? May 8, 2008 23:23 |
|
strcmp returns 0 when the strings are the same. so basically, stick a ! before those strcmps
|
# ? May 8, 2008 23:32 |
|
|
# ? May 18, 2024 03:54 |
|
Soldat posted:
|
# ? May 8, 2008 23:34 |