declaration

Declaring function parameters after function name

限于喜欢 提交于 2019-11-27 07:52:35
问题 int func(x) int x; { ............. What is this kind of declaration called? When is it valid/invalid including C or C++, certain standard revisions and compilers? 回答1: It's still valid, but it's pre-ANSI. That's actually where the K&R indent style got its name. The opening bracket is on the line after the function block because this looks weird: int func(x) int x; { ... } Anyway, this style is not recommended because of a problem with function prototypes. 回答2: That is K&R C parameter

Redeclaring a javascript variable

ⅰ亾dé卋堺 提交于 2019-11-27 07:45:36
In this tutorial there is written: If you redeclare a JavaScript variable, it will not lose its value. Why should I redeclare a variable? Is it practical in some situations? thank you It's nothing more than a reminder that if you do this: var x=5; var x; alert(x); Result will be 5. If you re-declare variable in some other languages for example - result will be undefined, or NaN, but not in javascript. An example of redeclaring a variable can be found in Google Analytics . When the JavaScript tracking code is initiated by the Google Analytics script, it declares or redeclares _gaq in this way:

Complex declarations

你说的曾经没有我的故事 提交于 2019-11-27 07:41:24
How do I interpret complex declarations like: int * (* (*fp1) (int) ) [10]; ---> declaration 1 int *( *( *[5])())(); --------> declaration 2 Is there any rule that should be followed to understand the above declarations? Here is a great article about how to read complex declarations in C: http://www.codeproject.com/KB/cpp/complex_declarations.aspx It helped me a lot! Especially - You should read "The right rule" section. Here quote: int * (* (*fp1) (int) ) [10]; This can be interpreted as follows: Start from the variable name -------------------------- fp1 Nothing to right but ) so go left to

JAVA Variable declaration not allowed here

折月煮酒 提交于 2019-11-27 07:32:54
问题 I get an error "Variable declaration not allowed here" and I don't know why, I'm new in java and can't find answer :/ As it says, I can't make "int" in "if" but is there a way to create it? import java.io.PrintWriter; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;import java.util.Scanner; public class test{ public static void main(String[] args) throws FileNotFoundException{ File plik = new File("test.txt"); PrintWriter saver = new PrintWriter("test.txt")

Assign values of array to separate variables in one line

∥☆過路亽.° 提交于 2019-11-27 06:35:20
问题 Can I assign each value in an array to separate variables in one line in C#? Here's an example in Ruby code of what I want: irb(main):001:0> str1, str2 = ["hey", "now"] => ["hey", "now"] irb(main):002:0> str1 => "hey" irb(main):003:0> str2 => "now" I'm not sure if what I'm wanting is possible in C#. Edit: for those suggesting I just assign the strings "hey" and "now" to variables, that's not what I want. Imagine the following: irb(main):004:0> val1, val2 = get_two_values() => ["hey", "now"]

Templates and headers question

不羁的心 提交于 2019-11-27 06:26:15
问题 The compiler says it can't find the reference for the function when I do this: // link.h template <class T> T *Link(T *&, T *(*)()) // link.cpp template <class T> T c:Link(T *&ChildNodeReference, T *(*ObjectCreator)()){ } If I implement inside the class on the header it goes smoothly. Please, I will work on the header until someone enlightens me about this. There are somethings in C++ that are weirdly annoying. I know, there is a reason for this and etc. Even so, can't the compilers help you

Complex C declaration

二次信任 提交于 2019-11-27 06:11:09
I was just going through some code on the Internet and found this: float * (*(*foo())[SIZE][SIZE])() How do I read this declaration? Is there a specific set of rules for reading such complex declarations? Kos I haven't done this in a while! Start with foo and go right. float * (*(* foo() )[SIZE][SIZE])() foo is a function with no arguments... Can't go right since there's a closing parenthesis. Go left: float * (*( * foo() )[SIZE][SIZE])() foo is a function with no arguments returning a pointer Can't go left further, so let's cross the parentheses and go right again float * (* (* foo()) [SIZE]

What are declarations and declarators and how are their types interpreted by the standard?

陌路散爱 提交于 2019-11-27 06:02:19
How exactly does the standard define that, for example, float (*(*(&e)[10])())[5] declares a variable of type "reference to array of 10 pointer to function of () returning pointer to array of 5 float "? Inspired by discussion with @DanNissenbaum Joseph Mansfield I refer to the C++11 standard in this post Declarations Declarations of the type we're concerned with are known as simple-declaration s in the grammar of C++, which are of one of the following two forms (§7/1): decl-specifier-seq opt init-declarator-list opt ; attribute-specifier-seq decl-specifier-seq opt init-declarator-list ; The

implicit class variable declaration in php?

自古美人都是妖i 提交于 2019-11-27 05:31:38
I've been looking at some code and am having a hard time working out variable declaration in php classes. Specifically it appears that the code i'm looking at doesn't declare the class variables before it uses them. Now this may be expected but I can't find any info that states that it is possible. So would you expect this: class Example { public function __construct() { $this->data = array(); $this->var = 'something'; } } to work? and does this create these variables on the class instance to be used hereafter? This works the same as a normal variable declaration would work: $foo = 'bar'; //

Variable definition inside switch statement

混江龙づ霸主 提交于 2019-11-27 05:25:18
In the following code, why is the variable i not assigned the value 1 ? #include <stdio.h> int main(void) { int val = 0; switch (val) { int i = 1; //i is defined here case 0: printf("value: %d\n", i); break; default: printf("value: %d\n", i); break; } return 0; } When I compile, I get a warning about i not being initialized despite int i = 1; that clearly initializes it $ gcc -Wall test.c warning: ‘i’ is used uninitialized in this function [-Wuninitialized] printf("value %d\n", i); ^ If val = 0 , then the output is 0 . If val = 1 or anything else, then the output is also 0. Please explain to