Rio Posted February 5, 2007 Report Posted February 5, 2007 Hi,für meine Anwendung benötige ich globale Variablen, die mit einem bestimmten Wert initialisiert werden, und genau da liegt mein Problem:wenn ich z.B. das global definiere:unsigned char test = 2;dann wird in meinem Programm die Variable "test" trotzdem mit 0 initialisiert. Versteh ich nicht. Anhand meiner Tests wird anscheinend alles auf 0 initialisiert und ich muss per hand in der Init() Fkt. die daten nochmal initialisieren (das frisst natürlich speicher)...oder mach ich was falsch? Übrigends wird mein Programm auch größer, sobald ich eine Initialiserung in der Deklaration vornehme...obwohl ja hier die Werte auf 0 bleiben..Kann mir das jemand erklären und was wäre nun die günstigste Variante?brauch man eigentlich dann werte, die mit 0 initialisiert werden sollen, nicht mehr explizit zu initialisieren, weil das automatisch geschieht? PS: Ist eine Initialisierung von Variablen in der Deklaration nur in C++ und nicht in C möglich? Quote
mess Posted February 5, 2007 Report Posted February 5, 2007 Hi Riothis is normal behaviour, I think that TK recommended the use of an init function in another threadI think that MIOS clears all variables on startup so that the initialisations don't have effectnot sure about this, otherwise it's an sdcc related issuethe other C compiler I have used (from Keil) initialises global variables as expectedI hope I did understand your question correctly, it would be easier if you would post your questions in English...Michaël Quote
Rio Posted February 5, 2007 Author Report Posted February 5, 2007 I hope I did understand your question correctly,it would be easier if you would post your questions in English...thx and sorry for german post... yes, seems that this is special at SDCC-Compiler. But i most wonder about the wasted memory if i initialise the variables at deklaration too....and they are always 0. So SDCC will init all variables at 0, i'm right? So i'll only need to initialise variables in init function, if values are different from 0, correct? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.