Go Down

Topic: How to fit a variable in a fixed position in ram (Read 1 time) previous topic - next topic


How do I assign variables to a fixed location in ram in C ?

I have a quite a few variables declared as static and what I would like to do is to place these variables in a set order and then later send these via serial in a set order by starting a ram address xx

Or should I just let the compiler take care of this ?




Well I would think letting the compiler take care of it, or at most use C pointer would be more then adequate to the task. Why you would want to add the burden to handle raw addressing of flash memory. seems like a flashback bad trip back towards assembly language. As as serial transmission is slower then processor time, what is the point or advantage gained?



Main reason is debugging really, dump 50 bytes etc., but also after speed, tho with the 32bit Due this is probably not going to be much of an issue.
But you are right, I do get flashbacks, lots at times.

Do I have to do it in Assembly or can this be done in C ?


Dec 05, 2012, 06:39 am Last Edit: Dec 05, 2012, 04:28 pm by Graynomad Reason: 1
You should be able to set a pointer to any place in memory, maybe something like this

byte * ptr  = (byte*)(0x1234);

That's probably not right, I always have to try every possible combination of these things to get the right syntax :)

But really what do you care where things are? It won't be any faster. Unless you have to address memory-mapped hardware it seems like an exercise in futility.

If your data elements are all the same use an array, if not use a structure.

Rob Gray aka the GRAYnomad www.robgray.com


Just really my lack of knowledge of C, but its improving heaps


Go Up