Josh Koffman wrote 2014-04-06 20:55: > > As for variables, I am going to try to be very conscious about how I > declare them. One thing I'm not entirely sure on, is what if my > project consists of multiple source files? As an example, suppose I > have a function in a different file (say, function.c). If I call that > function from my main loop, how would I have to define the variable? What variable? A variable that is (or not) part of the call as a parameter? A variable that has to be know to both the caller and the called? A variable that is only used localy withing the function? Different needs for different uses. :-) > Do I do it in the main loop, or as a global? If the declaration and the "use" are in different source file (that is, in different compiler runs), we go yet another "step up". What in MPASM is called external/global. The linker has to be told about that to be able to link it all correctly. No difference from when linking multiple ASM routines, actualy! > I know that technically I > could craft all my functions to take every single variable as an > argument, but that seems a bit unwieldy. Generally I keep a few > registers that I will set bits in for flags on how the program is > running, or what state it's in. I don't think I've fully grasped what > it means to declare something volatile, static, or just regular > global. It all depends on how and when a variable is used/needed. As an example, a variable for a normal I/O port (PORTA or something) is always "volatile" since the value can change without having a "PORTA=3Dnnn" in the code itself. So the value of the variable PORTA will never be cached or optimized, but always (re-) read from the source (the hardware I/O port) at each access/reference. That is "volatile" ! Same thing for a variable that sudenly could change becuse of an interrupt. Such code can't be optimized (to much) either. That is, the use/storage of that variable in main() can not be optimized, and should be declared volatile as "protection". And so on... :-) Jan-Erik. > > Thank you again! > > Josh > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .