Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,

I just want to clear up the issue or using "static" in BREW (C++)

I've read about it on the forums but people are saying a lot of different things.

Are you allowed:

1 - Static ints/bytes/shorts in a class
2 - CONST Static ints/bytes/shorts in a class
3 - static methods

- Thanks.

1 - Static ints/bytes/shorts in a class [NO]
2 - CONST Static ints/bytes/shorts in a class [NO]
3 - static methods [YES]

1 - Static ints/bytes/shorts in a class [NO]
2 - CONST Static ints/bytes/shorts in a class [NO]
3 - static methods [YES]

With GCC is possible to have [1] and [2].
Also, ADS supports [2], static const foo in a class is allowed, at least for integral types.

With GCC is possible to have [1] and [2].
Also, ADS supports [2], static const foo in a class is allowed, at least for integral types.

Hello bulach,
Quote:I just want to clear up the issue or using "static" in BREW (C++)
it is not abot GCC or ADS is about BREW.

Hello bulach,
Quote:I just want to clear up the issue or using "static" in BREW (C++)
it is not abot GCC or ADS is about BREW.

Hi, skumar_rao!
Well, if you use GCC to compile BREW applications, then it's possible to have static data. ;)
And also, even with ADS it's possible to have static const stuff...

Hi, skumar_rao!
Well, if you use GCC to compile BREW applications, then it's possible to have static data. ;)
And also, even with ADS it's possible to have static const stuff...

sorry you can have static const variables in BREW so
1 - Static ints/bytes/shorts in a class [NO]
2 - CONST Static ints/bytes/shorts in a class [YES]
3 - static methods [YES]

sorry you can have static const variables in BREW so
1 - Static ints/bytes/shorts in a class [NO]
2 - CONST Static ints/bytes/shorts in a class [YES]
3 - static methods [YES]

Please, don't get me wrong, just let me just clarify :)
1 - Static ints/bytes/shorts in a class [with ADS/RVCT: NO | with GCC: YES]
2 - CONST Static ints/bytes/shorts in a class [YES]
3 - static methods [YES]
The restriction on (1) is more about compiler (actually, linker option) than BREW itself... Anyone using GCC can sucessfully develop and, most important, deploy applications with statics in a class.
Anyway, for a truly "cross-compiler" compatibility, it's better to have some sort of "global" class wich would hold all your data, and access it like "((MyApp*)GETAPPINSTANCE())->global"

Please, don't get me wrong, just let me just clarify :)
1 - Static ints/bytes/shorts in a class [with ADS/RVCT: NO | with GCC: YES]
2 - CONST Static ints/bytes/shorts in a class [YES]
3 - static methods [YES]
The restriction on (1) is more about compiler (actually, linker option) than BREW itself... Anyone using GCC can sucessfully develop and, most important, deploy applications with statics in a class.
Anyway, for a truly "cross-compiler" compatibility, it's better to have some sort of "global" class wich would hold all your data, and access it like "((MyApp*)GETAPPINSTANCE())->global"

So the bottom line is:
As long as I use GCC to compile [I assume there are no drawbacks to this] I can use all 3 of the static types I mentioned above and everything should be happy ?
- Thanks.

So the bottom line is:
As long as I use GCC to compile [I assume there are no drawbacks to this] I can use all 3 of the static types I mentioned above and everything should be happy ?
- Thanks.

Yeap, with GCC you can use all the 3 types.
But I'd strongly recommend you using a "global" object placeholder, which can be accessed everywhere by GETAPPINSTANCE(). This way, you'll be easily port to ADS, if you ever need.

Yeap, with GCC you can use all the 3 types.
But I'd strongly recommend you using a "global" object placeholder, which can be accessed everywhere by GETAPPINSTANCE(). This way, you'll be easily port to ADS, if you ever need.

Ok thanks,
Its working in Visual Studio for const static integrals.
But Im getting "LNK2001 unresolved external symbol" for
class myClass
{
static byte *properties;
static int properties_length;
static byte *path;
static int path_length;
static byte **frameOffset;
static int frameOffset_length;
;
for example.
Why is this ? I assumed that static would mean the same thing in C++ as it does in Java, i.e. it belongs to that class rather than the instance etc..

Ok thanks,
Its working in Visual Studio for const static integrals.
But Im getting "LNK2001 unresolved external symbol" for
class myClass
{
static byte *properties;
static int properties_length;
static byte *path;
static int path_length;
static byte **frameOffset;
static int frameOffset_length;
;
for example.
Why is this ? I assumed that static would mean the same thing in C++ as it does in Java, i.e. it belongs to that class rather than the instance etc..

"Almost" the same as JAVA.
This is just a declaration, you need to actually initialize these statics, in your CPP, like:
int myClass::properties_length = 0;
...
int myClass::path_length = 0;
....

"Almost" the same as JAVA.
This is just a declaration, you need to actually initialize these statics, in your CPP, like:
int myClass::properties_length = 0;
...
int myClass::path_length = 0;
....

Perfect. Thats exactly what I needed to know.
Thanks very much.

Perfect. Thats exactly what I needed to know.
Thanks very much.

class Global
{
public:
static byte variable[256];
;
How do I initialise this in the CPP file ? (Whats the syntax I mean)
I obviously dont want to do :
static byte Global::variable[256] = {0, 0, 0, 0, 0, ..., n}
Is there an easier way ?
Thanks.

class Global
{
public:
static byte variable[256];
;
How do I initialise this in the CPP file ? (Whats the syntax I mean)
I obviously dont want to do :
static byte Global::variable[256] = {0, 0, 0, 0, 0, ..., n}
Is there an easier way ?
Thanks.

static byte Global::variable[256]={0}
this fills every element in the array with 0
don't forget the const ;)

static byte Global::variable[256]={0}
this fills every element in the array with 0
don't forget the const ;)

Just to make it clear... :)
When I said "Global" class, I mean to have a global class which you'd instantiate an object, to reference like "MyApp->global->member", and to be really globally accessible, ((MyApp*)GETAPPINSTANCE())->global->member so you don't need to have a MyApp ptr everywhere....

Just to make it clear... :)
When I said "Global" class, I mean to have a global class which you'd instantiate an object, to reference like "MyApp->global->member", and to be really globally accessible, ((MyApp*)GETAPPINSTANCE())->global->member so you don't need to have a MyApp ptr everywhere....

Thanks,
I cant make it const though as that seems to lock down all the values within the array strangely.

Thanks,
I cant make it const though as that seems to lock down all the values within the array strangely.

When it's not const, it will not work on real device

When it's not const, it will not work on real device

If you compile with GCC, it will work... :rolleyes:

If you compile with GCC, it will work... :rolleyes:

Thanks guys,
I started this thread to get to the bottom of the whole "Can I use Static stuff" debate.
Hopefully it has now achieved that.

Thanks guys,
I started this thread to get to the bottom of the whole "Can I use Static stuff" debate.
Hopefully it has now achieved that.

Yes, the limitation on static data can be overcome by compiling through GCC.

Yes, the limitation on static data can be overcome by compiling through GCC.

Hi all, still having problems though
// Script.h
class Script
{
static byte varialble[256];

//Script.cpp
static byte varialble[256] = {0};
Firstly if I do:
static byte Script::varialble[256] = {0};
as advised above I get the error: "Script:: storage-class specifier illegal on members"
I just want to make sure that "static byte varialble[256] = {0};" is correct.
Also, in another class if I refer to Script::varaible
#include "myClass.h"
#include "Script.h"
myClass::myfunction()
{
byte test = Script::variable[0];

I get an unresolved external symbol Script::variable.
What is the syntax for correct useage of statics in this manner ?
Thanks.

Hi all, still having problems though
// Script.h
class Script
{
static byte varialble[256];

//Script.cpp
static byte varialble[256] = {0};
Firstly if I do:
static byte Script::varialble[256] = {0};
as advised above I get the error: "Script:: storage-class specifier illegal on members"
I just want to make sure that "static byte varialble[256] = {0};" is correct.
Also, in another class if I refer to Script::varaible
#include "myClass.h"
#include "Script.h"
myClass::myfunction()
{
byte test = Script::variable[0];

I get an unresolved external symbol Script::variable.
What is the syntax for correct useage of statics in this manner ?
Thanks.