declaration

Static keyword in function declaration can be missing in function definition?

瘦欲@ 提交于 2019-11-30 12:54:51
I want to have a static function which I declare in my .c file before defining it: //file a.c version 1 static int foo(); ... static int foo() { ... } However, it seems that I can leave the static keyword out of the function definition and I get no compiler warnings... e.g. //file a.c version 2 static int foo(); ... int foo() { ... } Am I correct in assuming these two forms are exactly the same? If so, why is this discrepancy allowed and which form should I use? Yes 7.1.1/6 A name declared in a namespace scope without a storage-class-specifier has external linkage unless it has internal

What are the differences between $, @, % in Perl variable declaration? [duplicate]

落爺英雄遲暮 提交于 2019-11-30 11:58:57
问题 This question already has answers here : What is the difference between `$this`, `@that`, and `%those` in Perl? (5 answers) Closed 6 years ago . Example: my $some_variable; my @some_variable; my %some_variable; I know, @ seems to be for array, $ for primitive, is it totally right? What is % for? 回答1: One of the nice things about Perl is that it comes with a built in manual. Type in the following command: perldoc perlintro and take a look at the section Perl variable types . You can also see

What is the difference between these declarations in C?

巧了我就是萌 提交于 2019-11-30 10:19:33
In C and C++ what do the following declarations do? const int * i; int * const i; const volatile int ip; const int *i; Are any of the above declarations wrong? If not what is the meaning and differences between them? What are the useful uses of above declarations (I mean in which situation we have to use them in C/C++/embedded C)? const int * i; i is a pointer to constant integer. i can be changed to point to a different value, but the value being pointed to by i can not be changed. int * const i; i is a constant pointer to a non-constant integer. The value pointed to by i can be changed, but

how to set global const variables in python

时光怂恿深爱的人放手 提交于 2019-11-30 08:31:19
问题 I am building a solution with various classes and functions all of which need access to some global consants to be able to work appropriately. As there is no const in python, what would you consider best practice to set a kind of global consants. global const g = 9.8 So I am looking for a kind of the above edit: How about: class Const(): @staticmethod def gravity(): return 9.8 print 'gravity: ', Const.gravity() ? 回答1: You cannot define constants in Python. If you find some sort of hack to do

Redeclaration of a variable in a for-loop in C++

时光怂恿深爱的人放手 提交于 2019-11-30 08:28:10
When trying to compile the following (simplified) code for multiple platforms, I found that it was failing on some, namely IBM's xlC_r. Further investigation has found that it also fails on comeau and clang. It compiles successfully with g++ and Solaris's CC. Here is the code: int main() { int a1[1]; bool a2[1]; for (int *it = a1, *end = a1+1; it != end; ++it) { //... bool *jt = a2, *end = a2+1; //... } } xlC_r error: "main.cpp", line 8.25: 1540-0400 (S) "end" has a conflicting declaration. "main.cpp", line 6.25: 1540-0425 (I) "end" is defined on line 6 of "main.cpp". clang error: main.cpp:8

Figuring out C Declarations like: double (*b)[n]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 08:24:00
I'm trying to figure out some C declarations. What is the meaning of these C declarations? double (*b)[n]; double (*c[n])(); double (*d())[n]; double (*b)[n]; b is a pointer to an array of n doubles double (*c[n])(); c is an array of n pointers to functions taking unspecified number of arguments and returning double double (*d())[n]; d is a function taking unspecified number of arguments and returning a pointer to an array of n doubles In general, in order to parse these kind of declarations in your head, take the following approach. Let's see the last declaration, for example double (*d())[n]

default value of a variable at the time of declaration in C# and VB?

人盡茶涼 提交于 2019-11-30 08:15:40
Can anybody tell me what is the default value of a variable at the time of declaration in C# and vb?? In c# you can use the default keyword to determine default values. For example: default(bool) default(int) default(int?) Do you mean a (method) variable? or a field (on an instance or type)? For a method-level variable (in C# at least) it is irrelevant, since "definite assignment" means that you must give it a value before you can read it. Fields default to the bitwise zero state: for reference types (including string) that means null for Nullable<T> ( int? etc) that means null for numerics

Strange array return type

纵然是瞬间 提交于 2019-11-30 07:47:43
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"); System.out.println(Arrays.toString(words)); } prints [a, b, c, d, e] In the past, odd notations have been for "C" compatibility, but I wouldn't imagine someone writing this in C either. Does anyone know why this is even allowed? I am using Java 7 update 10, in case it matters. This does the same thing in Java 6. http://ideone.com/91rZV1 BTW this doesn't compile, nor would I

What is the difference between bind variables and the variable which I input using &&?

一个人想着一个人 提交于 2019-11-30 05:23:25
What is the difference between these two variable declarations? 1: num number:='&&num'; 2: variable num1 number; Since in both cases I can reference num by using &num or &&num in other files also, and in the case of bind variables :num1 . Moreover I have one more confusion: whether any of the below statements differ somehow, are they both valid and do they mean the same thing? 1: variable num1 number; 2: var num1 number; You appear to have some confusion about the differences between bind variables in Oracle and substitution variables in SQL*Plus. Let's start with substitution variables.

Why should member variables be initialized in constructors?

≯℡__Kan透↙ 提交于 2019-11-30 05:21:29
问题 When I first started working with object-oriented programming languages, I was taught the following rule: When declaring a field in a class, don't initialize it yet. Do that in the constructor. An example in C#: public class Test { private List<String> l; public Test() { l = new List<String>(); } } But when someone recently asked me why to do that, I couldn't come up with a reason. I'm not really familiar with the internal workings of C# (or other programming languages, for that matter, as I