Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


SiCrane

Member Since 09 Dec 1999
Online Last Active Today, 07:52 PM

#4935575 Pascal’s Triangle

Posted by SiCrane on 28 April 2012 - 06:39 AM

What have you tried? What parts are you having problems with?


#4935382 MSVC 2010 strange behavior

Posted by SiCrane on 27 April 2012 - 07:45 AM

In C++ local variables are always destroyed when program flow leaves the scope they were defined in. Unless you do the copy in that scope, it will be destroyed before the copy is made. The primary difference between compilers in this regard is exactly what they do when they destroy the objects. MSVC's debug mode will fill deleted memory with bit patterns that are likely to generate access violations. This makes it clear that you did something non-kosher like access memory previously owned by a now deleted object.


#4934716 Partial template specialization

Posted by SiCrane on 25 April 2012 - 06:11 AM

You can't specialize individual member functions of a template class without specializing the entire class.


#4933916 C# Bytes Overhead Question

Posted by SiCrane on 22 April 2012 - 06:54 PM

No, each variable has it's own alignment independent of what the alignment of what the other variables are. Alignment of other variables only affects what kind of space the compiler has to pack things together. For example:
struct Foo {
  byte b1;
  byte b2;
  short s1;
  int i1;
}
will have size eight, wasting no space. b1, b2 and s1 won't be forced to four byte alignment just because there's an int in the struct.


#4933908 C# Bytes Overhead Question

Posted by SiCrane on 22 April 2012 - 05:42 PM

It's called memory alignment and it's done because accessing bytes on an 8-byte boundary (the precise boundary depends on the hardware but is usually either 4 or 8 bytes)

This isn't quite right. If you read a single byte it doesn't matter what kind of boundary it's at. If you read two bytes at a time then it only needs to be at a multiple of two. If you read four bytes, it should be a multiple of four. A compiler isn't going to align every single data member to eight bytes. If you have a struct that looks like:
struct Foo {
  byte b1;
  byte b2;
  byte b3;
  byte b4;
}
it's only going to be four bytes long in total. None of the members need any special alignment so the compiler can pack them in tight.


#4933157 C# Syntax - Can anyone explain what [public static A B.C(D) {...}]...

Posted by SiCrane on 20 April 2012 - 06:08 AM

Did it look like the code for an explicit interface implementation?


#4932974 invalid conversion from 'char' to 'const char*'(using strings)

Posted by SiCrane on 19 April 2012 - 04:09 PM

You can also do:
setChar(std::string(1, alphabet[0])); // creates a string of length 1 consisting of alphabet[0] repeated 1 time
setChar(std::string(alphabet, 0, 1)); // creates a string of length 1 from string alphabet starting from the index 0



#4932852 C++ array and polymorphic objects

Posted by SiCrane on 19 April 2012 - 10:15 AM

You used to before the last site update, I don't know if it's gone missing due to deliberate decision or a bug.

Either way, if you think that writing insecure programs is perfectly fine, then I think it's clear that your advice should be ignored.


#4932618 Array Find Largest Recursively

Posted by SiCrane on 18 April 2012 - 05:00 PM

Let me be more explicit. Here:
myList[size-1] > findIndex(myList, size-1)
You're comparing a value in the list against the return value of findIndex(), which is an index.


#4931407 Structure Vector in class

Posted by SiCrane on 15 April 2012 - 06:10 AM

push_back() wants a copy of the object to be put into the container, not the components that make up the object. Give your struct a constructor and pass the relevant information to the constructor in the push_back() call.


#4931168 SDL_Events working in my main function but not in a class

Posted by SiCrane on 14 April 2012 - 06:02 AM

Is this your actual code? You seem to have a variable named events and another variable named Events. You probably want the events to be Events.


#4930574 GetClientRect coordinates question

Posted by SiCrane on 12 April 2012 - 08:18 AM

ClientToScreen() accepts a pointer to a POINT struct. When you pass it the address of the left or right member of a RECT you interpret the left and top members as a POINT or right and bottom members as a POINT struct, because those sets of variables follow each other in memory the same way as the members of a POINT struct.


#4928481 Smart pointers question

Posted by SiCrane on 05 April 2012 - 08:26 AM

Also, what about people writing single-threaded code (or properly scheduled multi-threaded code) -- why should their usage of shared_ptr be 100x slower, just in case you need their useless "thread safety" guarantee? Well written multi-threaded code doesn't need shared variables, so enforcing atomic counters is forcing a bad design choice onto your users...

Fortunately, boost has options for removing thread safety overhead if you're writing single threaded code. Defining BOOST_DISABLE_THREADS will disable thread support for all of boost (commonly done through boost/config/user.hpp) and BOOST_SP_DISABLE_THREADS will disable it for shared_ptr.


#4928197 Linking extern class instances

Posted by SiCrane on 04 April 2012 - 07:31 AM

The header is fine, but they only include declarations. That is, they tell the compiler that at some point someone is going to define those variables. Now you need to go and do just that. In a single source file you need to define the global variables without the externs. In your case you'd have:
CResourceManager *Resources;
CSceneManager *Scene;



#4927865 Include problems

Posted by SiCrane on 03 April 2012 - 07:56 AM

Some values that are "const" can appear in header files (integral values, I believe). Technically, these are implicitly "static", which means that each translation unit gets its own copy, and they aren't considered to be part of the list of objects for import/export. So "myOtherInt" could appear in globals.h.

Integral values aren't treated specially by const. Any const variable has implicit internal linkage and can therefore be placed in a header without generating duplicate symbol linker errors. However, it will still be the case for all types that each source file that includes that header will have a separate copy of that variable. For integral and other primitive types the compiler and linker will often be smart enough to be able to get rid of excess copies. For more complex types they often won't be.




PARTNERS