Questions tagged [declaration]

Declaration is the part of the subprogram (procedure or function) which provides the protocol(header), but not the body of the subprogram.

3407 questions
73
votes
6 answers

Strange array return type

Has any one seen the array [] placed after the method signature like this? public static String mySplit(String s)[] { return s.split(","); } public static void main(String... args) { String[] words = mySplit("a,b,c,d,e"); …
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
70
votes
8 answers

Complex C declaration

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?
Kaunteya
  • 3,107
  • 1
  • 35
  • 66
69
votes
13 answers

Strict mode in PHP

Other languages with automatic variable declaration - like Perl - have a strict mode. By activating this strict mode, variable declaration is required, and Perl throws an error as soon as you try to use an undeclared variable. Does PHP offer a…
jantimon
  • 36,840
  • 23
  • 122
  • 185
68
votes
13 answers

What is an 'undeclared identifier' error and how do I fix it?

What are undeclared identifier errors? What are common causes and how do I fix them? Example error texts: For the Visual Studio compiler: error C2065: 'cout' : undeclared identifier For the GCC compiler: 'cout' undeclared (first use in this…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
64
votes
14 answers

Eclipse Open declaration in Java project

In an Eclipse SVN project I have a problem; when I tried to open a declaration of one class, I got this error: Problems opening an editor Reason : projectname does not exist. Also refactoring does not work. I have searched the web and tried all…
Taegug
  • 641
  • 1
  • 5
  • 3
62
votes
5 answers

If two objects are declared in a single line, in which order are they constructed?

Let's say a class has been defined as class A { //..... }; and now I am creating two objects as A a,b; In what order are a and b created? Is it defined by the standard?
pasha
  • 2,035
  • 20
  • 34
60
votes
3 answers

forward declaration of a struct in C?

#include struct context; struct funcptrs{ void (*func0)(context *ctx); void (*func1)(void); }; struct context{ funcptrs fps; }; void func1 (void) { printf( "1\n" ); } void func0 (context *ctx) { printf( "0\n" ); } void…
user1128265
  • 2,891
  • 10
  • 29
  • 34
60
votes
11 answers

Define local function in JavaScript: use var or not?

When a local (inner) function is declared in JavaScript, there are two options: Declaring with var keyword, assigning to the variable: (function() { var innerFunction1 = function() { ... }; innerFunction1(); }()); Declaring just with the…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
58
votes
5 answers

Compiler error when declaring a variable inside if condition and no curly braces

Why does this first if compile well and the second fail? if(proceed) {int i;} // This compiles fine. if(proceed) int i;// This gives an error. (Syntax error on token ")", { expected after this token)
ironwood
  • 8,936
  • 15
  • 65
  • 114
55
votes
10 answers

How does the Java array argument declaration syntax "..." work?

I have been writing java for a while, and today I encountered the following declaration: public static void main(String... args) { } Note the "dot dot dot" in the array declaration, rather than the usual bracket []. Clearly it works. In fact I…
Virtually Real
  • 1,572
  • 4
  • 16
  • 20
55
votes
4 answers

What does it mean when there is a comma inside an array declaration? e.g. float[,]

I have some code I'm trying to understand while learning C#. I do not understand what I even need to search Google for to get here, but the code is as follows: float[,] heightAll = terData.GetHeights(0, 0, allWidth, allHeight); Why does the array…
ricky
  • 553
  • 1
  • 4
  • 4
52
votes
8 answers

Redeclaring a javascript variable

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
xralf
  • 3,312
  • 45
  • 129
  • 200
52
votes
8 answers

TS4023: Exported Variable has or is using name from external module but cannot be named

I've seen this answered before, but they don't seem to cover this specific use case (or they don't work/help) import {Route} from 'vue-router'; export const detailRoute = { path: '/detail/:id', component: Detail, props: (route: Route) => ({ …
user358089
51
votes
2 answers

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

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
  • 108,238
  • 20
  • 242
  • 324
50
votes
2 answers

Easy rule to read complicated const declarations?

For reading complex pointer declarations there is the right-left rule. But this rule does not mention how to read const modifiers. For example in a simple pointer declaration, const can be applied in several ways: char *buffer; // non-const pointer…
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182