C on Windows vs Linux - differences -


this code works on windows (visual studio), on linux gcc, produces incorrect results. can spot issues? work differently on linux vs windows?

is there way of compiling on linux? rather working gcc, if can me spot issues in code act differently on linux, great. -

returning this: char output[8]; char *x = output; return x;

for one, have plenty of code returns pointers local arrays, not allowed , cause undefined behavior when pointers de-referenced later. if code works in windows, you're being lucky since code not valid.

the 2 typical solutions are:

  1. have caller pass in pointer (and size_t length value prevent overwrite, of course!) string space called function allowed work.
  2. dynamically allocate new memory string inside function , return that. becomes caller's responsibility free() memory when it's no longer needed.

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -