definition

jquery - use a variable outside the function

喜你入骨 提交于 2019-12-01 03:39:19
问题 How I Can use a variable outside the function where it was declared? $(function() { function init() { var bwr_w = $(window).width(); } init(); $('#button').click(function() { alert('The Browser Height is' + bwr_w); }); }); If I click on the button I get this error: bwr_w is not defined 回答1: Just declare that variable in constructor's scope: $(function() { var bwr_w = null; function init() { bwr_w = $(window).width(); } init(); $('#button').click(function() { alert('The Browser Height is' +

Why is a non-static data member reference not a variable?

折月煮酒 提交于 2019-12-01 03:21:31
The definition of a variable in C++11 is as follows (§3/6): A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object. So a non-static data member reference is not a variable. Why is this distinction necessary? What's the rationale here? Here's one way I can declare a variable in C++: int scientist = 7; After this declaration (and definition, in this case), I can use scientist to read and set its value, take its address, etc. Here's another kind of declaration:- class Cloud { public:

Variable declaration and definition

限于喜欢 提交于 2019-11-30 23:56:54
int x; Is this a declaration or a definition? As I write the following code, #include <stdio.h> int main(void) { int x; printf("%p",&x); return 0; } it prints some address. So as memory is allocated, int x; can't be just a declaration. So is it a definition? From the C standard (n1256) : 6.7 Declarations ... 5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: — for an object, causes storage to be reserved for that object; — for a function, includes the function body; 101) — for an

Declarations, definitions, initializations in C, C++, C#, Java and Python [closed]

隐身守侯 提交于 2019-11-30 18:30:37
What do the terms mean in each of the above languages? Why do the languages differ (wherever they do, if at all they do) in this respect? C/C++: A declaration is a statement that says "here is the name of something and the type of thing that it is, but I'm not telling you anything more about it". A definition is a statement that says "here is the name of something and what exactly it is". For functions, this would be the function body; for global variables, this would be the translation unit in which the variable resides. An initialization is a definition where the variable is also given an

Initialization of Objects with Static Storage Duration in C vs C++ [duplicate]

佐手、 提交于 2019-11-30 18:15:35
Possible Duplicate: What does main return? For example, the following code compiles without any warning: #include <stdio.h> int i = i + 1; int main(int argc, char *argv[]) { fprintf (stderr, "%d\n", i); return 0; } I think this is illegal in syntax, because i is used before it's declared, is it right? And in my opinion, the appearance of int i = i + 1; is surely a bug, why doesn't the compiler warn about it? I use gcc 4.5.1. (notice: I'm referring to the current C++ standard) I'm not really sure about this, but, if my interpretation of the standard is correct, the code should be fine and not

“Multiple definition”, “first defined here” errors

﹥>﹥吖頭↗ 提交于 2019-11-30 17:33:27
I have 3 projects: Server , Client and Commons . Making header & source pairs in Commons doesn't cause any problems and I can access the functions freely from both Server and Client . However, for some reason making additional source/header files within Server or Client project always causes multiple definition of (...) and first defined here errors. Example: commands.h (in root dir of the Client project) #ifndef COMMANDS_H_ #define COMMANDS_H_ #include "commands.c" void f123(); #endif /* COMMANDS_H_ */ commands.c (in root dir of the Client project) void f123(){ } main.c (in root dir of the

What exactly is Reflection and when is it a good approach?

此生再无相见时 提交于 2019-11-30 12:01:25
问题 What exactly is Reflection? I read the Wikipedia article on this subject and I understand that it is a kind of meta-programming, where the program can modify itself at run-time, but what does this mean? In what kind of situations is this a good approach and when is it the best to use it? 回答1: Reflection is a facility where you can query an object about its attributes at runtime. For example, Python, Java and .Net have facilities where you can find the instance variables or methods of an

difference between baseline and benchmark in performance of an application

北城余情 提交于 2019-11-30 09:19:11
what is a baseline and what is a benchmark? what is the best definition for these and how do you baseline a set of numbers and benchmark another set? HI Gagneet, I'm on the Windows performance team: here is how we use these terms. A baseline is a measurement of a known configuration that is used as a reference for subsequent measurements. For base line, we characterize the thing being measured: lets take cold boot time for example. Here we have a set of machines that are well characterized - this means we know how they work, that we have good drivers for them, and that the hardware isn't

Neat way to define a long parameter vector in fortran

纵然是瞬间 提交于 2019-11-30 09:05:31
问题 Well, I've this problem now. I've a (huge) set of parameters I'd like to organize in a vector. Of course, I can do something like: real, dimension(64) :: CONST CONST(1) = 2.4 CONST(2) = 1.4 ... CONST(n) = CONST(1)*CONST(14)**CONST(7) ... CONST(64) = ABS(CONST(18)) (Note that some of the constants are related to other constants). But in that case, I wouldn't have the parameter attribute in the variable, wich I'd like to have. The other option I can think about is using the attribute parameter

How to define threadsafe?

六月ゝ 毕业季﹏ 提交于 2019-11-30 08:51:59
Threadsafe is a term that is thrown around documentation, however there is seldom an explanation of what it means, especially in a language that is understandable to someone learning threading for the first time. So how do you explain Threadsafe code to someone new to threading? My ideas for options are the moment are: Do you use a list of what makes code thread safe vs. thread unsafe The book definition A useful metaphor Eric Lippert says : When I'm asked " is this code thread safe ?" I always have to push back and ask " what are the exact threading scenarios you are concerned about? " and "