|
In java where and when do we use 'static int' and how does it differ from 'int'
Started by vini on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
int an integer....
static int: One variable per application Can be accessed without object.
Public static final int MAX = 10000; // Defined in MyClass // Somewhere else you could do int max be accessed per instance).
|
|
What is the right way of initializing a static map? Do we need a static function that will initialize it?
Started by Nithin on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Int> &m) { m[1] = 2; m[3] = 4; m[5] = 6; return true; } static map<int,int> m; static bool namespace boost::assign; map<int, int> m = map_list_of (1,2) (3,4) (5,6) (7,8);
I would wrap the map inside a static....
|
|
The comments on Steve Yegge 's post about server-side Javascript started discussing the merits of type systems in languages and this comment describes:
... examples from H-M style systems where you can get things like:
expected signature Int*Int->Int...
Started by devstopfix on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
So, (1, 2) would have ....
If you appreciate what static typing gives you, you'll learn how the type system of the programming language you with two elements.
I'd take Yegge's (and Ola Bini's) opinions on static typing with a grain of salt.
|
Ask your Facebook Friends
|
I've heard that, in C++, the static_cast function should be preferred to C-style or simple function-style casting. Is this true? Why?
Started by Tommy Herbert on
, 10 posts
by 10 people.
Answer Snippets (Read the full thread at stackoverflow):
Standard conversions between fundamental types:
double d = 3.14159265; int i = static_cast<int>(d is this supposed to do? char* c = (char*)new int( 5 ); //(2) that weird? char* c1 = static_cast<char*>( newObjection....
|
|
Hello.
I have a simple question. Is there a way ( using reflections I suppose ) to iterate all the static values of a class?
For instance
class Any { static int one = 1; static int two = 2; static int three = 3; public static void main( String [] args...
Started by Oscar Reyes on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Java.lang.reflect.*; public class Foo { public static int one = 1; public static int two = 2; public static int three = 3; public static void magicMethod( Class clz ) throws Exception { Field with almost....
|
|
I just saw a class (an big API module), where there is alot of stuff like
readParamString(Object params, int index)
and they have in that class 10 fields
final static int PARAM1 = 1 ... final static int PARAM10 = 10
which are being used with readParam...
Started by Navarium on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Public static final int LOAD_ACTION = 1; public static final int SAVE_ACTION = 2; public static final int DELETE_ACTION = 4; public static....
Meaning to the literal value then it might be more useful; e.g .
|
|
Could somebody please elaborate on the differences?
Started by Evan Fosmark on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Further, static_cast is....
No checks on the validity.
It might be a static(int) foo compares most to c++ reinterpret_cast<int> , i.e.
The difference is that (int)foo can mean half a dozen different things.
Of the cast.
|
|
Try to see which cast is faster (not necessary better): new c++ case or old fashion C style cast. Any ideas?
Started by Andrei on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Using mov dword ptr [x],eax int y = static_cast<int>(d); 013A1402 fld qword ptr [d] 013A1405 call] int x =....
Be no difference at all if you compare int() to equivalent functionality of static_cast<int>() .
|
|
Gcc complains about this:
#include <stdio.h> static const int YY = 1024; extern int main(int argc, char*argv[]) { static char x[YY]; }
$ gcc -c test1.c test1.c: In function main': test1.c:5: error: storage size of x' isn't constant test1.c:5: error...
Started by Simon Elliott on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
1024 static int const YY = 1024; enum{ ZZ = 1024 }; extern int main(void){ static char x[XX]; // no error *(int*)&XX = 123; // error: lvalue required as unary ‘&’ operand static char y[YY]; // error static....
|
|
Struct A { static const int a = 5; struct B { static const int b = a; }; }; int main() { return A::B::b; }
The above code compiles. However if you go by Effective C++ book by Scott Myers(pg 14); We need a definition for a in addition to the declaration...
Started by Pradyot on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
However:
struct A { static const int a = 5; struct B { static const int b = a; }; }; int mainC++ compilers allow static const integers (and integers only) to have their value specified in the code (it is typically....
|