- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code seems not to work with the compilers mentioned above on Linux OS.
[cpp]
#include <vector>
#include <iostream>
typedef unsigned long T; // doesn't work
//typedef unsigned int T; // works
int main()
{
std::vector<T> fibonacci;
fibonacci.push_back( T(0) );
fibonacci.push_back( T(1) ); // works for just 2 elements
fibonacci.push_back( T(1) ); // doesn't work with 3 elements (and "unsigned long" and auto)
//fibonacci.push_back( T(2) ); // works again with 4 elements
auto fib( fibonacci ); // doesn't work
//std::vector<T> fib( fibonacci ); // works
for( int i = 0; i < fib.size(); ++i )
std::cout << fib << ", ";
std::cout << std::endl;
return 0;
}
[/cpp]
Output:
[bash]
[SHELL]> g++ -std=c++0x main.cpp && ./a.out
0, 1, 1,
[SHELL]> icpc -std=c++0x main.cpp && ./a.out
6303744, 1, 1,
[/bash]
Valgrind output (We suspect the output to be correct due to 0 initialization of memory):
[bash]
[SHELL]> valgrind ./a.out
==1734== Memcheck, a memory error detector
==1734== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==1734== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==1734== Command: ./a.out
==1734==
==1734== Invalid read of size 8
==1734== at 0x400FCD: main (in ~/a.out)
==1734== Address 0x5b0b140 is 0 bytes inside a block of size 24 free'd
==1734== at 0x4C273B8: operator delete(void*) (vg_replace_malloc.c:480)
==1734== by 0x400FB8: main (in ~/a.out)
==1734==
0, 1, 1,
==1734==
==1734== HEAP SUMMARY:
==1734== in use at exit: 0 bytes in 0 blocks
==1734== total heap usage: 4 allocs, 4 frees, 80 bytes allocated
==1734==
==1734== All heap blocks were freed -- no leaks are possible
==1734==
==1734== For counts of detected and suppressed errors, rerun with: -v
==1734== ERROR SUMMARY: 3 errors from 1 contexts (suppressed: 5 from 5)
[/bash]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem we experienced originated in a templated function. The 'T' just a remained during simplification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page