0

UPDATE Hm, I have an update. Apparently my huge array of "unsigned long long fhash[105][100555]" was not getting initialized to zero automatically in vC++... It worked when I did = {0}. Isn't it supposed to initialize automatically?

I'm doing contest programming, and I usually compile with g++ at school/ideone etc... but I have to use a VC++ 2010 compiler.

That said, I have code to do polynomial rolling hashing (like used in Rabin-Karp), but do these overflow differently on these compilers?

Code is here: http://pastebin.com/UFdpwHCt (hashing is around line 67)

Output is here: https://i.stack.imgur.com/03Np0.png

How come "bhash" is equal between the two compilers, but "fhash" isn't? They are hashed using the same method... In the G++-3 output, the "fhash" and "bhash" outputs are the same (they are supposed to be) but in the VC++-10 output the "fhash" and "bhash" aren't the same...

I'm using the overflow to let it mod itself naturally, to speed up execution, instead of explicitly modding it with a large prime.

dave
  • 209
  • 2
  • 8
  • [`include `](http://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio) and use `uint??_t` of whatever size you need. (Probably [this](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml) is not relevant, but I'm think it worth reading in your case. Section regarding your question is [here](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Integer_Types#Integer_Types)). – Aleksei Zabrodskii Nov 01 '12 at 23:07
  • Hm, I have an update. Apparently my huge array of "unsigned long long fhash[105][100555]" was not getting initialized to zero automatically in vC++... It worked when I did = {0}. Isn't it supposed to initialize automatically? – dave Nov 01 '12 at 23:48
  • 1
    No, it won't be zeroed implicitly (unless you allocate memeroy with [`calloc`](http://www.cplusplus.com/reference/clibrary/cstdlib/calloc/), but why you wanna do it in C++?). Memory block will contain random stuff, actually, which could happen to be all zeroes, but you should never rely on that, of course. (See ISO C++ Standard for details.) – Aleksei Zabrodskii Nov 02 '12 at 13:58

1 Answers1

0

Wasn't an issue. the issue was that it wasn't getting initialized to zero. fixed it using memset.

dave
  • 209
  • 2
  • 8