Name: Anonymous 2012-10-07 21:47
template <size_t N>
void print_members(int (&arr)[N]) { ... }
so is C++ going to create a new function for every different sized array I use
template <size_t N>
void print_members(int (&arr)[N]) { ... }
void print_members(int* arr, int N) { ... }
print_members<SOME_CONSTANT>(arr);
void (*fn)(int*) = print_members<SOME_CONSTANT>;
void print_members__18(int *a) { print_members(a, 18); }
void print_members__42(int *a) { print_members(a, 42); }
void (*fn)(int*) = print_members__18;
func(5);
func(18);
func(29);
func(62);
...
func(2);
func(8);
int arr[] = { 5, 18, 29, 62, ... 2, 8 };
for(int i = 0; i < sizeof(arr)/sizeof(arr[0]);i++)
func(arr[i]);
std::cout << "Hello world" << std::endl;
usually compiles into a 500K~ binary.
printf()
), dynamically linked is 16KB for both, dynlink + custom link options is 2.5KB for the cout and 1.5KB for printf. Cutting out the startup code gets it down to 2KB for the cout and 1KB for the printf. .bss stripping turns the printf one into 636 bytes (mostly header bloat), and 1547 for cout which is still 2.5x bigger. Why MS didn't default to settings which produce the last two sizes is anyone's guess...