|
Vanadium posted:T sum = T(); should work in all cases I can think of.
|
# ? Dec 4, 2008 20:27 |
|
|
# ? May 19, 2024 01:16 |
|
ultra-inquisitor posted:What about matrices? Mightn't they be constructed to the identity matrix, rather than all zeros? Is there a more standard method which doesn't rely on the implementation of the type? I can write a type that responds to any specific attempt to initialise it by blowing up your harddrive, so I doubt it.
|
# ? Dec 4, 2008 20:30 |
|
Ledneh, you can give them an interface that allows them to pass in whatever they want. Something like this (untested) code:code:
code:
BigRedDot fucked around with this message at 21:06 on Dec 4, 2008 |
# ? Dec 4, 2008 20:57 |
|
Thanks BigRedDot, that looks like a solution I can make work. Didn't occur to me to try templating setCallback. (edit) As far as performance goes, it's not a real-time project, and I've always been taught never to optimize as I go anyway (with the "unless it's totally obvious" caveat of course). So one extra indirection doesn't bother me at all. Ciaphas fucked around with this message at 21:14 on Dec 4, 2008 |
# ? Dec 4, 2008 21:07 |
|
ultra-inquisitor posted:What about matrices? Mightn't they be constructed to the identity matrix, rather than all zeros? Is there a more standard method which doesn't rely on the implementation of the type? If this is a concern, just provide the initial value as a default parameter code:
|
# ? Dec 4, 2008 21:17 |
|
The Red Baron posted:If this is a concern, just provide the initial value as a default parameter
|
# ? Dec 4, 2008 21:23 |
|
Ledneh posted:The second is the same way, except I count on the rest of the team to use boost::bind where needed. Cleaner and less error-prone for me, and probably more type-safe, but the rest of the group has to learn how (and remember) to use boost::bind. Function object adapters are part of the STL, and boost::bind is easier to use than the standard ones so I wouldn't worry about the rest of the group.
|
# ? Dec 4, 2008 21:56 |
|
BigRedDot, I implemented your solution in my test bed, and it works great, but I have one question. I was discussing this elsewhere too, and the question came up as to whether or not for your templated SetCallback you have to include a template parameter. My compiler (Sun CC) can get away with SetCallback(Type::blah, obj), but someone else reported their compiler giving up until they did SetCallback<Type>(Type::blah, obj). I assume you're supposed to have to specify the template parameter explicitly?
|
# ? Dec 4, 2008 22:04 |
|
Ledneh posted:BigRedDot, I implemented your solution in my test bed, and it works great, but I have one question. I was discussing this elsewhere too, and the question came up as to whether or not for your templated SetCallback you have to include a template parameter. You should only have to do that if the type is not present in the function arguments, i.e.: code:
|
# ? Dec 4, 2008 22:15 |
|
No I don't think you should need to. I use some almost identical code to set up some middleware callbacks. We use various versions of gcc, and I never have to specify the template parameter explicitly. I use code just like what I posted above with Handler and OtherHandler. What compiler is complaining?
|
# ? Dec 4, 2008 22:16 |
|
(edit) "MSVC 2008 with service pack 1" In the meantime, another question. Right now the relevant bits of my real-world class look like this: code:
code:
Ciaphas fucked around with this message at 23:00 on Dec 4, 2008 |
# ? Dec 4, 2008 22:56 |
|
Ledneh posted:so that I could at least have them together to make it easier to keep synced, but it didn't take, with an error about templated typedefs being an anachronism. Is there anything I can do about this, or am I more or less stuck? Template typedefs don't exist, and they won't until the next standard.* Just make the second overloaded version call the first, which should pick up any errors. i.e. code:
|
# ? Dec 4, 2008 23:06 |
|
Youse a drat genius. Or I'm just dumb as a rock. Either way, thanks muchly (edit) so it does. I guess this proves that the latter statement is true at least | V Ciaphas fucked around with this message at 00:10 on Dec 5, 2008 |
# ? Dec 4, 2008 23:11 |
|
Ledneh, what AD shows is what I had up in the example I posted, and what I use in my own code at work. As for the compiler, I haven't done any windows development since 1995, so I really don't know anything at all about MSVC. Maybe someone else can speak to its quirks and peccadilloes.
|
# ? Dec 4, 2008 23:17 |
|
So the IRC krew knows I have been having a little trouble with yacc, trying to parse a small subset of Verilog. I need to change the type of yylval to char * so I can store string tokens in it and grab those in the parser. My productions work, I just need to change yylval from it's default type of int to char *. I have tried #define YYSTYPE char * and extern YYSTYPE yylval; I know I have to do something like that somewhere, whenever I put that in however yacc tells me code:
So basically, I just need to know how to declare yylval properly. Here is my scanner - http://rafb.net/p/Qm8ANp74.html and my grammar - http://rafb.net/p/dI1Iu111.html Night Chaos fucked around with this message at 00:44 on Dec 5, 2008 |
# ? Dec 5, 2008 00:21 |
|
You're doin' it wrong. #define YYSTYPE char * goes in the yacc file, not the lex file.
|
# ? Dec 5, 2008 00:33 |
|
That problem fixed, why now will everything parse properly except my gates. http://filer.case.edu/dsu/vparse.tar Makefile and test input file included, it'll do everything except gates, and I can't see why. Somebody could look at my grammar productions with fresh eyes and see some missing token or something?
|
# ? Dec 5, 2008 03:40 |
|
You're trying to print the yylval of the gate type and you aren't specifying a yylval in the lexer. Either strdup the yytext for all your gates or make different productions for each gate type.
|
# ? Dec 5, 2008 03:45 |
|
code:
The only thing I could figure was if fq was ever negative and index was a power that would result in imaginary numbers. But fq is (in the main code) read from a file, which contains only positive numbers, and I checked that it read correctly, all positive. What else could cause it to return NaN? Thanks in advance.
|
# ? Dec 5, 2008 04:17 |
|
DontMockMySmock posted:
Why don't you break it up into multiple lines and use a debugger?
|
# ? Dec 5, 2008 04:41 |
|
Updated version of my parser and scanner, current problem is that the macro to define yylval as a char * isn't working. As described http://dinosaur.compilertools.net/bison/bison_6.html#SEC44 Line 2 of gram.y sure has that definition right there, but I still get code:
http://rafb.net/p/sdc81r24.html y.tab.h Night Chaos fucked around with this message at 05:51 on Dec 5, 2008 |
# ? Dec 5, 2008 05:45 |
|
DontMockMySmock posted:
Is it possible that one or more of coef, fq[i] and index are very small positive numbers such that the expression coef*pow(fq[i],index) evaluates to a number that is indistinguishable from 0 in single-precision floating point representation? (Anything smaller than 2-149) If this is the case you may benefit from using doubles instead of floats. But yeah, either use a debugger or just printf some intermediate parts of the calculation and see where it goes awry for your particular inputs. Smackbilly fucked around with this message at 07:36 on Dec 5, 2008 |
# ? Dec 5, 2008 07:33 |
|
is there a way to use sizeof to get the size of a pointer? nm i'm an idiot
|
# ? Dec 5, 2008 16:25 |
|
DontMockMySmock posted:
|
# ? Dec 5, 2008 16:56 |
|
nm didn't see the nm
|
# ? Dec 5, 2008 17:29 |
|
ultra-inquisitor posted:It's just for my own edification, I was wondering if there was some cool language feature I didn't know about that might facilitate it. I'm still pretty inexperienced at generic programming. You could use template specialization if you didn't want to always have to pass in "zero" into the function. You basically would create a template class with a static function "GetZero" (or whatever) which would return zero as defined by that type (either 0, or the identity matrix, or whatever you wanted). something like this: code:
code:
|
# ? Dec 5, 2008 22:03 |
I'm getting a sigabrt on a delete. I know it's a memory management problem, but I don't see why...code:
|
|
# ? Dec 6, 2008 08:40 |
|
Jo posted:I'm getting a sigabrt on a delete. I know it's a memory management problem, but I don't see why...
|
# ? Dec 6, 2008 09:36 |
|
Jo posted:I'm getting a sigabrt on a delete. I know it's a memory management problem, but I don't see why... Why wouldn't you just use a smart pointer there?
|
# ? Dec 6, 2008 09:49 |
|
DamageInc posted:
|
# ? Dec 6, 2008 11:06 |
ultra-inquisitor posted:Is runGaussian3x3 in a different DLL, or are you using new[] to allocate the memory? Right now it's just new[]. Avenging Dentist posted:Why wouldn't you just use a smart pointer there? vv Guess I'll have to, but I still don't see why it doesn't work. Perhaps I have a horrid and fundamental misconception about pointers. code:
EDIT: I got rid of 'delete gaussian' at the end of the function and the program works. I'm not sure why, exactly, and I'm probably leaking memory; it terminates shortly after returning from the function, so I'm not terribly worried. EDIT 2: Only for you, Otto Skorzeny. A typo in the gaussian function made this: Jo fucked around with this message at 18:40 on Dec 6, 2008 |
|
# ? Dec 6, 2008 18:27 |
|
If you have valgrind you can check whether you're leaking memory pretty easily (as long as your program doesn't have a long run time as-is). e: hey put that image back up it was
|
# ? Dec 6, 2008 18:35 |
Otto Skorzeny posted:If you have valgrind you can check whether you're leaking memory pretty easily (as long as your program doesn't have a long run time as-is). Yup, it would seem a leak is present. ==17230== LEAK SUMMARY: ==17230== definitely lost: 2,718,128 bytes in 16 blocks.
|
|
# ? Dec 6, 2008 18:50 |
|
If you allocate memory with new[], you have to deallocate it with delete[].
|
# ? Dec 6, 2008 19:02 |
Vanadium posted:If you allocate memory with new[], you have to deallocate it with delete[]. Yes, I'm readily aware, but when I call delete[], I get a sigabrt. EDIT: Aaah, I see what you're saying. No, it's just a simple Image * gaussian = new Image( blahblah ). The delete still delete, in this case, no? Jo fucked around with this message at 19:36 on Dec 6, 2008 |
|
# ? Dec 6, 2008 19:24 |
|
It should be, barring some retarded nonstandard semantics.
|
# ? Dec 6, 2008 19:41 |
|
Do you still get the behavior if you run the snipped version? That is, if you just create it and delete it immediately after?
|
# ? Dec 6, 2008 20:14 |
|
What does the destructor for Image do? Is it possible that the constructor does something with the pointer to img and then something funky happens in the destructor?
|
# ? Dec 6, 2008 20:39 |
schnarf posted:What does the destructor for Image do? Is it possible that the constructor does something with the pointer to img and then something funky happens in the destructor? Image is largely a wrapper for another image library with import/export functionality. code:
|
|
# ? Dec 7, 2008 01:53 |
|
|
# ? May 19, 2024 01:16 |
|
This one had me stumped for a hour or so at work before I got pulled away. When I compile my application everything works fine. When it tries to link I get " undefined reference" to everything in the threadqueue class (Quick wrapper around STL queues to make it threadsafe). There has to be something so obviously stupid here but I can't see it. threadqueue.h code:
code:
code:
$ $ strip threadqueue.o $ -rw-rw-r-- 1 me me 432 Dec 9 04:26 threadqueue.o
|
# ? Dec 9, 2008 05:28 |