|
Sounds like it's a legitimate warning. Any particular reason you narrowed those indices?
|
# ? Aug 18, 2008 01:02 |
|
|
# ? Apr 25, 2024 08:44 |
|
ehnus posted:Sounds like it's a legitimate warning. Any particular reason you narrowed those indices? It didn't take much work to change them from int to char, due to the way my source is laid out. All of these variables are small numbers and could never be more than about 100, so there was no worry about them getting bigger than 127 and wrapping around into negative numbers. And the reason why I chose to do it was just that there are quite a lot of them and it seemed prudent not to use four times as much memory for them as was needed. For example, one of them is an eight by five by forty-three tridimensional array of integers. That's quite a lot of numbers, none of them (in this case) bigger than about 25, so making them char instead of int seemed a good idea.
|
# ? Aug 18, 2008 01:34 |
|
I'd be willing to bet that due to member padding within data types that the savings you see by narrowing those types won't actually be realized
|
# ? Aug 18, 2008 02:05 |
|
ehnus posted:I'd be willing to bet that due to member padding within data types that the savings you see by narrowing those types won't actually be realized If your "optimization" causes a bunch of warnings, saves less than 1KB of RAM, and is probably slower, it's not worth it.
|
# ? Aug 18, 2008 02:08 |
|
"Premature optimization is the root of all evil." - Donald Knuth
|
# ? Aug 18, 2008 02:18 |
|
I want to populate a set with objects, but I'm getting unusual errors.code:
code:
code:
|
# ? Aug 18, 2008 03:59 |
|
operator< needs to be a const member function.
|
# ? Aug 18, 2008 04:02 |
|
Ah, so it's "bool coordinate::operator<(const coordinate &right) const{" Of course! I see now that the error message basically told me what I needed to implement. Too bad my brain skipped over that last "const" every time I read it. Thanks
|
# ? Aug 18, 2008 04:19 |
|
magicalblender posted:Ah, so it's "bool coordinate::operator<(const coordinate &right) const{" Of course! I see now that the error message basically told me what I needed to implement. Too bad my brain skipped over that last "const" every time I read it. Thanks Correct. Technically it's not required to make right a const reference, but it's good practice since it eliminates a superfluous copy.
|
# ? Aug 18, 2008 04:21 |
|
Hammerite posted:Hey again.
|
# ? Aug 18, 2008 04:40 |
|
Mustach posted:What's already been said about this is true. The reason for the warnings is that char is not guaranteed to be signed or unsigned, unlike int. If you still want char variables, declare them as either signed or unsigned (or static_cast to one of those when you do the indexing) and the warnings will go away. Thank you very much. I made them all "unsigned char" instead of "char" and the warnings have disappeared.
|
# ? Aug 18, 2008 13:18 |
|
I have a new question, about member functions of classes. I have worked with constructors before, but I have not worked with other member functions of classes. In the file classes.h there is the following definition of a class, "button": code:
code:
code:
code:
Yet when I try to compile this, for each line like the above I get the following error messages: "'class button' has no member named 'destroybutton'" "'class button' has no member named 'ensurebutton'" Why does it say that there's no such function when there clearly is, and I've even defined the function further up in the same file?
|
# ? Aug 19, 2008 18:41 |
|
Hammerite posted:Why does it say that there's no such function when there clearly is, and I've even defined the function further up in the same file? I can't see any obvious problems, but would you mind sticking the .CPP and .H files on Pastebin or something so we can see it all in context?
|
# ? Aug 19, 2008 18:45 |
|
Hammerite posted:In the file classes.h there is the following definition of a class, "button": destroybtn != destroybutton ensurebtn != ensurebutton Also, why are you using a macro for BUTTONX? Just use a constant if you need a constant.
|
# ? Aug 19, 2008 18:46 |
|
That Turkey Story posted:destroybtn != destroybutton Bah, how'd I miss that
|
# ? Aug 19, 2008 18:47 |
|
Ugg boots posted:Bah, how'd I miss that Upgrade your copy of vdiff
|
# ? Aug 19, 2008 18:48 |
|
Oh god, how stupid well, thanks!
|
# ? Aug 19, 2008 18:54 |
|
That Turkey Story posted:destroybtn != destroybutton There are lots of different macros, about 50 in all. I am using them so I can insert a new entry somewhere in the array "buttons", and then just update all of the macros above the appropriate number instead of finding everywhere they're used in the file. The reason why I am using an array is that there are some times where I have a line that looks like code:
|
# ? Aug 19, 2008 18:58 |
|
Hammerite posted:There are lots of different macros, about 50 in all. I am using them so I can insert a new entry somewhere in the array "buttons", and then just update all of the macros above the appropriate number instead of finding everywhere they're used in the file. Using a constant instead of a macro doesn't in any way affect your ability to do this
|
# ? Aug 19, 2008 19:04 |
|
KaeseEs posted:Using a constant instead of a macro doesn't in any way affect your ability to do this But it does, because if I have lines in lots of different places that say, for example, code:
But if I just had code:
|
# ? Aug 19, 2008 19:08 |
|
What? How iscode:
code:
|
# ? Aug 19, 2008 19:10 |
|
KaeseEs posted:What? How is I guess I must be, at least I definitely have the impression now that I'm confusing some terms.
|
# ? Aug 19, 2008 19:19 |
|
An array may not be the ideal data structure for this application.
|
# ? Aug 19, 2008 19:20 |
|
I am working on continuing/forking a game and I have a severe problem. The original devs were, quite possibly, on crack. Is there any recommended program out there to clean code with? The program's written in C++ very erratically but I really, really don't wanna rewrite it.
|
# ? Aug 20, 2008 00:18 |
|
The Cursed Seeker posted:I am working on continuing/forking a game and I have a severe problem. Depends on what kind of crack they were smoking. If the brace/indent style is psychotic, there are a million pretty-printers that will fix it for you (as well as most editors). If there are some issues with the design and naming of classes and functions, many editors (esp. Java and C# editors, for whatever reason) have refactoring tools that may assist you with this. If the architecture is bad, or there's a mishmash of stupid decisions sprinkled through the code, fixing that is AI-hard, and you'll have to do it yourself.
|
# ? Aug 20, 2008 10:09 |
|
I wrote a simple little c program that forks and the child execs another little program. Before the fork, I set up an alarm and signal handler. Now, I thought the child was entirely replaced (in memory) by whatever program it execs, yet the child still seems to be terminated by the alarm I set before the fork. Can someone set me straight please?
|
# ? Aug 21, 2008 08:24 |
|
my stepdads beer posted:I wrote a simple little c program that forks and the child execs another little program. Before the fork, I set up an alarm and signal handler. Now, I thought the child was entirely replaced (in memory) by whatever program it execs, yet the child still seems to be terminated by the alarm I set before the fork. http://www.opengroup.org/onlinepubs/000095399/functions/fork.html Are you sure you haven't got the parent/child processes mixed up?
|
# ? Aug 21, 2008 09:49 |
|
TSDK posted:This page does confirm that the alarm should have been cancelled: Well they both terminate at the same time (both are writing to stdout continuously). I can't find the child process running after either. Have I written a zombie?
|
# ? Aug 21, 2008 10:28 |
|
my stepdads beer posted:Well they both terminate at the same time (both are writing to stdout continuously). I can't find the child process running after either. Have I written a zombie?
|
# ? Aug 21, 2008 11:41 |
|
TSDK posted:I also seem to remember that there are calls you can make to detach a child so that this doesn't happen. I think you can also fork twice if you want to detach from the parent. Edit: that said, if you kill the parent the child should be adopted by init. Something is going wrong here, tef fucked around with this message at 14:06 on Aug 21, 2008 |
# ? Aug 21, 2008 14:02 |
|
tef posted:I think you can also fork twice if you want to detach from the parent. my stepdads beer posted:Before the fork, I set up an alarm and signal handler.
|
# ? Aug 21, 2008 14:28 |
|
Mustach posted:What does the handler do and what program does the child exec? The handler catches SIGALRM and just exits. The child process is just an infinite loop counting from 0 to 9 and writing to stdout.
|
# ? Aug 22, 2008 02:58 |
|
Mustach posted:Who forks twice? That doesn't make any sense; it's possible to have a whole family tree of processes, each having up to some big number of children. Because when you fork you are responsible for cleaning up your child processes, no ifs ands or buts, but if you end before the child does then the init process takes over. So if you want to just fire-and-forget a child process, what you do is: code:
EDIT: screwed up my terminology a bit, C is not a "daemon" it's just a process running in the background with no parent. daemons have a bunch more conditions they have to meet. Setting up a daemon also involves forking twice, but for a different reason. JoeNotCharles fucked around with this message at 06:38 on Aug 22, 2008 |
# ? Aug 22, 2008 06:36 |
|
I get what you mean, but I guess I don't think of that as "forking twice" since each process only forks once.my stepdads beer posted:The handler catches SIGALRM and just exits. The child process is just an infinite loop counting from 0 to 9 and writing to stdout.
|
# ? Aug 22, 2008 14:18 |
|
I updated the OP with some more links from here: http://forums.somethingawful.com/showthread.php?noseen=0&threadid=2779598&pagenumber=21#post348190891
|
# ? Aug 25, 2008 00:30 |
|
Is there an elegant way of handling the issue of using template templates whose parameter count is not "technically" equal to the template parameter count of the class supplied to it, but where this other class provides default parameters for the non-considered parameters? Okay, that's a pretty lovely description, so consider this instead:code:
Until C++0x brings along template typedefs, the only thing I can think of is indirecting the whole thing through some dummy class that lets default parameters actually be used, like so: code:
|
# ? Aug 25, 2008 14:00 |
|
The Red Baron posted:Until C++0x brings along template typedefs, the only thing I can think of is indirecting the whole thing through some dummy class that lets default parameters actually be used, like so: This method is what is used right now, even in the STL -- that's pretty much how allocator passing and some_allocator::rebind works (allocator instantiations basically double as their own wrapper by design). STL containers don't take template template parameters for their allocator argument even though they logically could. This was done both because template template support was not common in 1998 and because it would mean that your allocator template would require the exact same amount of arguments as was specified in the template parameter list. Both of these problems are solved by adding a level of indirection as in your example.
|
# ? Aug 25, 2008 20:10 |
|
That Turkey Story posted:This method is what is used right now, even in the STL -- that's pretty much how allocator passing and some_allocator::rebind works (allocator instantiations basically double as their own wrapper by design). STL containers don't take template template parameters for their allocator argument even though they logically could. This was done both because template template support was not common in 1998 and because it would mean that your allocator template would require the exact same amount of arguments as was specified in the template parameter list. Both of these problems are solved by adding a level of indirection as in your example. Do you know if variadic templates will resolve this issue, or are variadic templates qualitatively different from n-ary template types?
|
# ? Aug 25, 2008 20:45 |
|
Avenging Dentist posted:Do you know if variadic templates will resolve this issue, or are variadic templates qualitatively different from n-ary template types? Do mean will you be able to pass variadic templates as non-variadic template arguments? I don't immediately see a reason why you shouldn't be able to, but whether you actually can is a different story.
|
# ? Aug 25, 2008 21:43 |
|
|
# ? Apr 25, 2024 08:44 |
|
That Turkey Story posted:Do mean will you be able to pass variadic templates as non-variadic template arguments? I don't immediately see a reason why you shouldn't be able to, but whether you actually can is a different story. Well, I mean that, and the inverse: using a variadic template as a template parameters to take non-variadic template types as arguments. i.e.: code:
|
# ? Aug 25, 2008 21:55 |