Re: Array of Long
2009-03-06 by Graham Davies
--- In AVR-Chat@yahoogroups.com, David VanHorn <microbrix@...> wrote: > I have an array of longs that > I need to feed out my Uart ... David, in the statement: UDR = &(Proc_Data[Proc_Data_Out_Index])+i; on the right hand side you take the address of an array element and add i. What is puzzling you is why the result jumps up four at a time. The reason is that the address of the array element is a typed pointer. In other words, the compiler knows that it's the address of a long and will treat it as such. For each "one" you add to the value of this pointer, the compiler will move forward four bytes, so as to point to the next long object in memory. A solution is to discard the type by casting the address to a number. A better solution would be to cast the address of the entire array to be a pointer to bytes. It is then clearer in the program text what you are trying to do, which is to treat an array of longs as an array of bytes for some specific purpose. Remember to multiply the number of longs in the array by sizeof ( long ) to get the number of bytes. Or, if the length of the array is known at compile time and you want to send it all, just use sizeof ( Proc_Data ). Graham.