Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

136 Neutral

About Azune

  • Rank
  1. Anyone know? If not I'll try comp.lang.c++.
  2. Quote:Original post by SiCrane Don't divide by the sizeof the struct. Just subtract the pointer to the first index. Pointer arithmetic on typed pointers already includes the division. Good point, why didn't I notice that. Assuming the passed address is a gtRGB pointer then subtraction works. If it's not then you could cast both the array and passed address to char* and stick with the division.
  3. One of my worst bugs involved '#pragma pack(1)'. I had it enabled in the networking module to make message packets as small as possible (I avoid it normally because it slows execution down by messing up alignments). Unfortunately it had become enabled in a few other modules through liberal inclusion of header files. The result being that different parts of the application had different ideas of the sizes of various objects. It took me half a night of painstaking debugging to figure this out. Objects appeared to be changing between the 'call main.[0040xxxx]' instruction and the 'push ebp' instruction setting up the stack frame right at the start of the called function. In reality the objects weren't changing but were viewed differently by the two different functions. The moral of the story? Include only what you need and be careful when using #pragma pack. As I progress as I programmer I seem to make fewer bugs and I almost never trip up on things like uninitialised/null pointers anymore but when I do add a bug it usually takes a while for me to find and correct it :\.
  4. Azune

    Delete USB

    Depends on whether the usb filesystem completely overwrites the file when it deletes or just removes the reference to the file. Either way recovering a file wouldn't be straight forward. You'd somehow need to get an image of the entire usb disk and manually find your (possibly corrupt and/or fragmented) files within that. Do you need to get these files back that bad? I don't suppose they ended up in the recycle bin?
  5. It's a bit of a hack but it should work, even in practice. If the struct/class is padded then that extra size will be included in the value given by sizeof(). Each element of the array will be located a multiple of sizeof(gtRGB) away from the start of the array so you can divide by sizeof(gtRGB) and get the correct integral result. By the way, you should be able to do: ((Passed Address) - goArray) / sizeof(struct gtRGB) Since array indexing is just syntactic sugar for pointer arithmetic: '&array[0]' == '&*(array + 0)' == '&*array' == 'array' The compiler probably loses the redunant deference/addressing anyway (certainly if optimisation is on) but it doesn't hurt to do it yourself and it makes the code simpler. EDIT: Beaten to it :\. I should reply quicker and spend less time checking my post for errors. [Edited by - Azune on July 30, 2005 11:58:30 AM]
  6. All the exception types are hurting my eyes :\. If all you're going to do upon catching an exception is report it you might as well throw a generic exception with a descriptor field explaining the exception. On the other hand if you are going to recover then have specific types for each recoverable exception as you're doing at the moment. In regards to your new problem, you might try handling the exceptions you've thrown or you will, unsurprisingly, get "unhandled exception" errors at run time. Adding the following catch block to WinMain should do the trick: catch (const DirectXError& e) { // Do stuff ... } AFTER THOUGHT: Quote: I really didnt understand this. What do you mean by C code? Its all C++. Do you mean that the function CALLBACK is "C code"? All your code is C++, but Windows was written in C. When you call DispatchMessage you are telling the API to call WndProc with the message (which is why it's a callback function). So what SiCrane was suggesting is that having an exception thrown in WndProc propagate back through the C code in the API that called it could be causing problems. I'm not sure whether this is the case or not, you'd need to step through the assembly carefully in a debugger (as well as sound knowledge of how exception handling works under the hood) to find out. I've got a feeling that it's not a good idea though. It may appear to work sometimes and then crash when you least expect it. [Edited by - Azune on July 30, 2005 10:09:43 AM]
  7. Here is a very simplified version of the smart pointer I'm working on. It will involve simulating intrusiveness by doing some extra stuff during allocation via an overloaded new operator (hacked and unportable I hear you cry :p). #include <cstdlib> template<class T> class sptr { public: class new_flags {}; T* p; }; template<class T> void* operator new(size_t size, const typename sptr<T>::new_flags& flags) { // Do stuff ... } template<class T> void* foo(size_t size, const typename sptr<T>::new_flags& flags) { // Do stuff ... } int main() { // This won't compile: // int* p = new(sptr<int>::new_flags()) int(123); // Neither will this: // void* q = foo(0, sptr<int>::new_flags()); // However this will: void* r = foo<int>(0, sptr<int>::new_flags()); } I get this error when compiling: Quote: ptr.cpp: In function `int main()': ptr.cpp:25: error: no matching function for call to `operator new(unsigned int, sptr<int>::new_flags)' <internal>:0: note: candidates are: void* operator new(unsigned int) It doesn't seem to be able to see my overloaded new. When I couldn't solve this I tried changing the function from 'operator new' to 'foo'. Again it didn't compile with implicit instantiation, but did compile with explicit instantiation. So basically I need to know how I can explicity instantiate my overloaded new operator or if it's even possible. I tried the following: void* p = operator new<int>(0, sptr<int>::new_flags()); which works but obviously will only allocate the memory, not construct the object. Thanks in advance for any help you are able to offer. PS: I am aware that there are good existing implementations of smart pointers but I'm still playing with my own version because programming is a hobby I enjoy doing. Hopefully that should ward off unhelpful shouts of 'use boost::shared_ptr' ;).
  8. Also a->b.c->d looks nicer than (*(((*a).b.c)).d, or something like that :\
  9. Quote:Original post by Physics515 yea one more question, this time about Assembly. Do you have to develop on the same processor type that your running you OS on or can you develop on one and run on another. Don't take this the wrong way but if you have to ask questions like this you aren't ready to develop an OS. You should master the Assembly language of your target processor first. If it's Intel then grab the processor manuals off their site. They cover all the basics you need, like loading the GDT and switching to protected mode. You should also learn C as well. I don't know C# but I think they're similar so you shouldn't have much trouble. Anyway good luck with your project, even if you don't finish you'll learn a lot from it. EDIT: And to answer your question, you can develop on a different architecture provided you have a cross compiler/assembler.
  10. Azune

    SuSE Linux

    I've got SuSE 9.1 on my laptop right now and it works great. I can use my DVD burner (with k3b) and it even recognises my mp3 player without installing any extra drivers. Webcam support isn't very good though. I managed to get mine working using a third party driver but it's tempermental and only works when a certain combination of usb devices are connected. There is a difference between the personal and professional version though. I spent a while wondering where all the compilers were before I realised that the personal version doesn't included any development software. You can always download all the extra packages from the ftp site, but it's nice to have the on your original cd. I really wouldn't bother with dual booting if I were you, SuSE should have everything you need. The only thing I really miss about Windows are certain games and I shouldn't really be wasting time on those while at uni anyway ;).
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!