I'm interested in using data structures in assembly code, similar to how data structures are used in C. That is, you define a data structure type and then declare a name as a specific instance of that data structure type -- and then put it all within an include file (in C this is a .h header file). Then include that file within the various code files that reference the named data structure. Also, one of the code files allocates memory for the named data structure, and the linker puts it all together.
I wanted to do that with TI DSP assembly code, using the .struct directive, plus the .include directive. I presumed it would all work just fine, and I couldn't find any warnings to the contrary in the user guides.
I ran into a problem.
I am using linear assembly code (files with the .sa file extension). [Note: I LOVE the TI linear assembly optimizing compiler!] But when used in the above described manner, it doesn't work. And here is my best explanation of why. The optimizer eliminates unused variables (which makes sense). However, the data structure declared in the .include file ends up getting eliminated, because that files 'sees' no allocation for that data structure. The data structure has been optimized out-of-existence. Then the compiler complains about unresolved references to the now-gone data structure.
I tried various solutions. One pseudo-solution was to make the memory allocation *known* to the including file, either by doing the memory allocation within the included file, or within the including file -- either way, the allocation is now visible within the including file, so the compiler makes no complaint. But both those are pseudo-solutions, because when this is done multiple times (for multiple including files) it ends up allocating memory for the same data structure many times over.
I haven't yet found a solution. Any solutions?