Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualdarkhaven3

Posted 19 December 2012 - 12:32 PM

this will become tragically clear once you'll try to debug a big project where everything can talk and modify everything else.. at that point it becomes really hard to figure out what's going on... this, again, has nothing to do with OOP but more to do with global state and basic programming theory.
Of course, from a programmer's point of view, being able to access every function and every variable feels like a good thing, but it quickly turns into a total mess... and the problem gets bigger as the software gets bigger, so you might get away with it with small code bases.

I think I can safely say that the above is pretty much a nonexistent issue. In C, you cannot "access every function and every variable"; a static int declared within a function remains within the scope of that function, and cannot be overwritten directly. Of course, it's quite possible to do so intentionally, in the same way that it is with any OOP language that doesn't do bounds checking on arrays, if you get where I'm going with that.

If I don't want a function to modify something, I'll pass it a pointer-to-const (i.e. const int* var; ). If I want a variable to be available locally to a function, I will initialize that variable within the function that requires it. Not much more to it than that, honestly. If it comes to a point where data is being modified that I didn't intend to be modified, I can always have a look at that nifty map file the linker generates, which is available to both C and C++ programs.

#1darkhaven3

Posted 19 December 2012 - 12:30 PM

I think I can safely say that the above is pretty much a nonexistent issue. In C, you cannot "access every function and every variable"; a static int declared within a function remains within the scope of that function, and cannot be overwritten directly. Of course, it's quite possible to do so intentionally, in the same way that it is with any OOP language that doesn't do bounds checking on arrays, if you get where I'm going with that.

If I don't want a function to modify something, I'll pass it a pointer-to-const (i.e. const int* var; ). If I want a variable to be available locally to a function, I will initialize that variable within the function that requires it. Not much more to it than that, honestly.

PARTNERS