I am using the attached code snippet macros in our code for swapping bytes.
Problems i observed are:
1)when i give 8 byte value to SWAP_8BYTES(x) MACRO it is crashing. This is happening only for Release build in visual studio. Swap works fine for Debug build.
Is this because of any memory related issues? Please comment.
That crash was because of an access violation. Are you sure it's the macro that causes it ?
Can you show the code that is using the macro ? Can you also indicate the line that the debugger refers to when the crash occurs ?
srimallikarthik
ASKER
I feel this is because of marco, i tried replacing my swap macro with the attached code macro which i found in some article. It is working superb.. ( means no crash)
There's no way to tell without first knowing what causes the crash.
Just a feeling is often not good enough. Please try running the code in a debugger, and figure out where it crashes exactly. This assumes that your IDE allows you to run release code in a debugger heh. Alternatively, you can add some debugging output of your own to narrow it down to the exact line where it crashes.
Zoppo
I made a simple test application with VS 2010 to test both macros:
>> Though comments didn't point out the actual solution for the problem, it helped in resolving the issue.
So, what was the issue ?
I'm sure it wasn't in the macro that you showed, as I told you in http:#35793073.
We could have assisted you better if you would have given us the extra information I asked for in that same post :)
Infinity08
>> Problem was because of the compiler optimization which lead our macro go mad in release build.
Could you clarify that ? How did it go mad ? And how did it cause an access violation ? That doesn't make much sense, since the macro isn't accessing any memory.
srimallikarthik
ASKER
What i did is, just disabled the compiler optimization from "maximum speed" to "disabeld" in project settings and built the project in release build. IT WORKED(no crash). So i concluded its because of compiler optimization.
And YES, it is because of macro (optimization). The another macro which i mentioned swapeightbytes(x) is not calling another macros inside. It is expanded completely at compile time unlike the other macro which expands further while preprocessing which created problem because of optimization.
It's surprising that VC++ would optimize at the preprocessing stage, because that doesn't make a lot of sense.
Disabling optimization indicates that it is indeed likely a problem related to the way VC++ optimizes the code. However, that doesn't mean the problem had anything to do with the macro. It still seems highly unlikely that the access violation was caused by the macro.
If I were you, I'd investigate this a bit further (with our help if you want), to make sure that the issue is actually resolved, and not just hidden. I assume it's not an option for you to keep optimization disabled for the release target, so that's a further reason to track down the root cause.
Zoppo
@srimallikarthik: Which version of Visual Studio do you use? I built my test app with VS 2010 with all speed-optimizations turned on and everything works fine ...
srimallikarthik
ASKER
i am using VS2008
i will check my same on VS2010. lets see.
As you mentioned it seems unlikely that access violation occurs. I didn't get time to dig into that :(.
What kind of crash are you talking about ?