Compile C++ Code to behave the same in Windows and Linux -
i've installed cygwin , use program c++ on windows.
i prefer write code (these assignments) in windows code needs able run on linux. while code ports of time appears there things work on windows cause segfaults on linux (such referencing uninitialized variables , pointers).
i compile using g++ in both windows (via c:\cygwin\bin\g++.exe) , linux, don't understand why code works in former fails in latter (or why don't behave same). how code behave same in both? possible?
i not using windows specific libs though c++ noob may misunderstanding simple/important. lastly know using uninitialized variables , pointers bad - i'd use cause segmentation faults in windows.
what describing "referencing uninitialized variables , pointers" called undefined behaviour. means "your luck may vary" - may in 1 way on 1 system, , else on different system. unfortunately, part of "c , c++ supposed efficient languages", behaviour of undefined behaviour - compiler doesn't need care it, , there nothing in c or c++ standard defines supposed happen.
if apply -wall
compiler, should give warnings types of uninitialized variables.
make rule whenever declare variable, assign value. it's never bad idea this. if it's assigning useless value, it's better trying identify why calculation goes wrong somewhere deep inside four-level nested loop.
you can try using microsoft visual studio tools - there free "express edition" of these tools. if compile debug mode, generate code (attempt to) detect use of uninitialized variables.
i'm not aware of "library" allows fault on uninitialized variables.
Comments
Post a Comment