This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array with names

hello to all of you,
is there a way to have a array and give each element of the array a special name?
An example:

float my_array[20];
.
.
for(i=0;i<20;i++)
send(my_array[i];
.
.
and each element of the array should have its special name like
1. actual_temperature
2. minimum_temperature
3. maximal_temperature
but the should share the same memory adress.

Sorry dont tell me Please read the manual, just give me a helpful hint.
Sincerly yours

  • I don't understand your requirement. You'll have to provide a more elaborate description and/or example.

  • "is there a way to have a array and give each element of the array a special name?"

    No.

    However, you could use an enum to give names to the index values, and use them.

  • is there a way to have a array and give each element of the array a special name?

    Yes, and no. Yes, it's possible, but the thing you have can't be called an "array", then. That's what C has structs for.

    but the should share the same memory adress.

    This completely fails to make sense. Array elements don't do that from the beginning.

    Sorry dont tell me Please read the manual, just give me a helpful hint.

    Now you're being arrogant, ridiculous, or both. How can you possibly know that Please read the manual isn't exactly the helpful hint you need?

    Actually, what you should read is not a manual. You're completely confused about basic aspects of programming in C. You should stop worrying about ARM, Keil and uVision, and go back to learning basic C skills. In that sense, you'll have to Please read the manual, but only later --- you desperately need to RTF textbook first.

  • Could you possibly be wanting something as simple as the preprocessor's text substitution?

    #define actual_temperature  my_array[1]
    #define minimum_temperature my_array[2]
    #define maximal_temperature my_array[3]

  • "should share the same memory adress"

    For that, you'd need a union

  • "Sorry dont tell me Please read the manual"

    Why do you say that?

    Do you suspect that reading the manual would actually answer your question, but you're just can't be bothered to do it?

  • Hallo to everybody. Now being back from camping-holiday in Italia i wana thank you for your help.

    #define actual_temperature  my_array[1]
    #define minimum_temperature my_array[2]
    #define maximal_temperature my_array[3]
    

    this fits perfect to my requirements, thank you Dan, i would have send you a picture-postcard from Pisa if i have had your adress ;-)

    This hint is very helpful, everybody needs a little help if there are tomato-slices on front of your eyes ;-)

  • this fits perfect to my requirements,

    It is a fairly ugly way to do this and will confuse the heck out of anyone trying to maintain it.

    Use a union instead. At least this makes it clear which array you're actually referencing to.

  • this fits perfect to my requirements

    Then why not just declare these three variables instead of an array?

    Or make them fields in a struct, so you can send the entire block of three variables with one call to the send() routine.

  • this fits perfect to my requirements,

    It quite definitely doesn't --- it clearly fails the "have the same address" criterion. And neither is it perfect, in any useful interpretation of the word. A struct would be a whole lot more readable.

  • #define actual_temperature my_array[1]
    #define minimum_temperature my_array[2]
    #define maximal_temperature my_array[3]

    hides the fact that it is an array wheras
    #define MY_ARR_actual_temperature 1
    #define MY_ARR_minimum_temperature 2
    #define MY_ARR_maximal_temperature 3

    and accessing it by my_array[MY_ARR_actual_temperature]
    would not

    I consider it important that an 'array indicator' e.g. MY_ARR_ be included in the offset name, I have found horrendous bugs where the offset from your_array was used on my_array creating a very tough bug (nobody could 'see' it). e.g. if no 'array indicator' was included, could you spot your_array[actual_temperature] in a reasonable time?

    Erik