static variable | developer.brewmp.com static variable | developer.brewmp.com

Developer

static variable

Forums:

Why cant we use static variable in our BREW applications.what would be the consequences if we use one? Can we use static functions? Why is there restriction on Global varialbles also?

i havent found satisfactory answers to these queries till date.Plzzzz help.

are you really interested in WHY? you should better ask WHAT TO DO INSTEAD. Because you just can't... think of it like of hardware limitation.
Consequences of using would be that your application won't link.
But, you can use static functions.
And you have your applet structure, place your globals there.

are you really interested in WHY? you should better ask WHAT TO DO INSTEAD. Because you just can't... think of it like of hardware limitation.
Consequences of using would be that your application won't link.
But, you can use static functions.
And you have your applet structure, place your globals there.

frankly speaking i have an idea what one should do. i am really interested in WHY is there such a limitation. And if we can use static functions, then why not static variables??i also 9 how we can declare globals in applet structure.

frankly speaking i have an idea what one should do. i am really interested in WHY is there such a limitation. And if we can use static functions, then why not static variables??i also 9 how we can declare globals in applet structure.

Couple of reasons:
1) Global and static variable requires space to be allocated in the data segment. BREW mod file format doesn't allow data segment because of the following reason.
2) In a position independent system like BREW, there are no absolute address in which application binary will be loaded. When you declare static/global data you need to know the address of the variable, BREW system does not have the capacity to calculate new address of the variable based on the arbitrary load address. Static function on the otherhand is an entry in the symbol table.

Couple of reasons:
1) Global and static variable requires space to be allocated in the data segment. BREW mod file format doesn't allow data segment because of the following reason.
2) In a position independent system like BREW, there are no absolute address in which application binary will be loaded. When you declare static/global data you need to know the address of the variable, BREW system does not have the capacity to calculate new address of the variable based on the arbitrary load address. Static function on the otherhand is an entry in the symbol table.

Thanx for the reply.But there is alwaz an entry in the symbol table for evry variable also.Inany case, then where does the lines of code for a static function reside.The symbol table stores the address only.And as u said BRW cant find absolute addresses from relative addresses.Then how are functions managed.
Plzzzz i wud like to have some more details bcos the information supplied seems to be a bit insufficient for me to inderstand the actual scenario.

Thanx for the reply.But there is alwaz an entry in the symbol table for evry variable also.Inany case, then where does the lines of code for a static function reside.The symbol table stores the address only.And as u said BRW cant find absolute addresses from relative addresses.Then how are functions managed.
Plzzzz i wud like to have some more details bcos the information supplied seems to be a bit insufficient for me to inderstand the actual scenario.

The keyword "static" for a function means something quite different than for a variable. The code for functions (both static and extern, there's really no difference after linking) goes in a program's text section. Static variables go into a program's data section. MOD files do not support a data section. For BREW to support static variables, not only would the loader have to be changed, but BREW would also have to take care of updating the register used for for finding these variables whenever the app context changes.

The keyword "static" for a function means something quite different than for a variable. The code for functions (both static and extern, there's really no difference after linking) goes in a program's text section. Static variables go into a program's data section. MOD files do not support a data section. For BREW to support static variables, not only would the loader have to be changed, but BREW would also have to take care of updating the register used for for finding these variables whenever the app context changes.

Mark,
Your post is very informative and interesting. It begs the question though - why does this work with GCC, but not with ADS? Same hardware, same BREW...
markb wrote:The keyword "static" for a function means something quite different than for a variable. The code for functions (both static and extern, there's really no difference after linking) goes in a program's text section. Static variables go into a program's data section. MOD files do not support a data section. For BREW to support static variables, not only would the loader have to be changed, but BREW would also have to take care of updating the register used for for finding these variables whenever the app context changes.

Mark,
Your post is very informative and interesting. It begs the question though - why does this work with GCC, but not with ADS? Same hardware, same BREW...
markb wrote:The keyword "static" for a function means something quite different than for a variable. The code for functions (both static and extern, there's really no difference after linking) goes in a program's text section. Static variables go into a program's data section. MOD files do not support a data section. For BREW to support static variables, not only would the loader have to be changed, but BREW would also have to take care of updating the register used for for finding these variables whenever the app context changes.

whm wrote:Mark,
Your post is very informative and interesting. It begs the question though - why does this work with GCC, but not with ADS? Same hardware, same BREW...
I've made some posts on this before:
http://brewforums.qualcomm.com/search.php?searchid=121473
Basically, for position independent code, GCC represents globals differently than ADS.

whm wrote:Mark,
Your post is very informative and interesting. It begs the question though - why does this work with GCC, but not with ADS? Same hardware, same BREW...
I've made some posts on this before:
http://brewforums.qualcomm.com/search.php?searchid=121473
Basically, for position independent code, GCC represents globals differently than ADS.

Mr Markb,
thanx for ur interest in the topic but the link you specified does yield anything.either the URL is incorrect or it has become obsolete.plz check. i wud really like to go through ur posts.

Mr Markb,
thanx for ur interest in the topic but the link you specified does yield anything.either the URL is incorrect or it has become obsolete.plz check. i wud really like to go through ur posts.

This means that there is no way i can generate a .mod file for a code with static variables in it. is there any thing which can be done to compile a code for arm which has static.
My actual problemis that i have to port a code for J2Me to BREW and it has extensively used static variables.I want to know is there no way i can use static variables in the code. Do i have to change the logic through out.

This means that there is no way i can generate a .mod file for a code with static variables in it. is there any thing which can be done to compile a code for arm which has static.
My actual problemis that i have to port a code for J2Me to BREW and it has extensively used static variables.I want to know is there no way i can use static variables in the code. Do i have to change the logic through out.

ankitaggarwal wrote:This means that there is no way i can generate a .mod file for a code with static variables in it.
You can. You just have to use GCC.

ankitaggarwal wrote:This means that there is no way i can generate a .mod file for a code with static variables in it.
You can. You just have to use GCC.

After that will the application(.mod file) run as any other usual mod file does???
or there are some other settings that need to be made somewhere.

After that will the application(.mod file) run as any other usual mod file does???
or there are some other settings that need to be made somewhere.

------
ankitaggarwal wrote:After that will the application(.mod file) run as any other usual mod file does???
Yes.

------
ankitaggarwal wrote:After that will the application(.mod file) run as any other usual mod file does???
Yes.