|
From: | Graham Davies |
Subject: | Re: [avr-gcc-list] string initialization using "" and { } |
Date: | Wed, 27 May 2009 10:12:34 -0400 |
Zoran Rilak wrote:
I can't find an explanation ... why there should be a difference in the generated code for string vs. array-of-chars initializers.
If you declare a string and then use it as an initializer for an array of characters, the compiler will arrange for the string to be stored somewhere and then copy it to the array to perform the initialization. Should you need the string "abd" elsewhere in your program, the same copy might be used. None of this applies to initializing each element of the array separately. The compiler is at liberty to generate code that uses literals, which is more efficient. The initializer values are not available for reuse elsewhere.
Graham.
[Prev in Thread] | Current Thread | [Next in Thread] |