declaration

Function Pointer Declaration - what does __P do?

倖福魔咒の 提交于 2019-11-29 19:10:48
问题 The usual form of function pointer definitions is: int function(int, int); int (*ptr)(int, int); but I saw a form today which I didn't understand. Can anyone explain this please? int (*close) __P((struct __db *)); 回答1: The __P() macro is usually used to support C implementations from the days of K&R C, when there were no prototypes (which were introduced to C with C89). Basically the logic is #if SOME_LOGIC_TO_TEST_WHETHER_IMPLEMENTATION_SUPPORTS_PROTOTYPES # define __P(argument_list)

Is “int a;” a declaration or definition in C and in C++?

不羁岁月 提交于 2019-11-29 19:00:20
问题 Is int a; a declaration or definition in C? Is there any difference in C++? I was always thinking it's just a declaration, until today... Is it a declaration or a definition? 回答1: A declaration describes an object, whereas a definition requests the creation of an object. All definitions are also declarations , but the reverse is not true. In the case of int a; , what it is depends on where it is placed in the source code: Within a function, int a; is a definition - it requests the creation of

when to pass a parameter and when to use an instance variable

孤者浪人 提交于 2019-11-29 18:48:10
How do you guys decide between keeping track of something locally and then just passing it in to every method you call on it, or declaring an instance variable and using it in the methods? I tend to prefer instance variables kept in a list at the end of the Class. But as my programs become more and more complicated, this list gets longer and longer... I figure that if something is getting passed often enough it should just be visible to all the boys and girls who need it, but then I start wondering, "why not just make everything public! Then there will be no more need of passing anything at

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

可紊 提交于 2019-11-29 18:02:02
问题 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? 回答1: Yes 7.1.1/6 A name

What's the difference between these two java variable declarations?

别等时光非礼了梦想. 提交于 2019-11-29 16:10:26
public class SomeClass { private HashSet<SomeObject> contents = new HashSet<SomeObject>(); private Set<SomeObject> contents2 = new HashSet<SomeObject>(); } What's the difference? In the end they are both a HashSet isn't it? The second one looks just wrong to me, but I have seen it frequently used, accepted and working. Alan Geleynse Set is an interface, and HashSet is a class that implements the Set interface. Declaring the variable as type HashSet means that no other implementation of Set may be used. You may want this if you need specific functionality of HashSet . If you do not need any

VB 2010 'variable' is not declared. It may be inaccessible due to it's protection level

前提是你 提交于 2019-11-29 15:14:50
i'm sort of a n00b to VB and was wondering how to make a variable available across multiple Subs. It's just a test app to get familiar with VB. My Code: Public Class Sentences Private Sub SentenceBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SentenceBox.TextChanged If Me.Text = Trim(Sentence) Then MsgBox("Good job!") Main_Menu.Show() Me.Close() End If End Sub Private Sub ABCs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim random As Integer = CInt((Rnd() * 10) + 1) Dim Sentence As String Select Case random Case 1

What is the difference between these declarations in C?

跟風遠走 提交于 2019-11-29 15:01:17
问题 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)? 回答1: 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

Can a variable be defined only in the scope of an if-statement, similar to how it's often done for for-loops?

﹥>﹥吖頭↗ 提交于 2019-11-29 15:00:28
Is there a way to declare, assign and compare a variable to an expression in an if construction in such a way that it is only defined in the scope of the if construction? This works (declare and assign, but of course the condition is only the return value of function f being equal to zero or not): int main() { if(int i = f()) { printf("%d", i); // i is defined here! } else { // Here too! } // But not here! } But when I try to compare the value of i with an actual expression I run into trouble: int main() { // Does not compile because "int i = f()" is not a primary expression? if((int i = f())

unmanaged var as member of managed class c++

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:14:10
I'm novice in .net c++ and trying to create class looking like: public ref class Klient { public: Klient(){} // zmienne static DWORD klienty[41][2]; static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje }; but MSV says that: error C4368: cannot define 'klienty' as a member of managed 'Klient': mixed types are not supported What's wrong with this code? You can have .NET basic data types as members of your managed class (static int i), or pointers to anything unmanaged (DWORD* pid, HANDLE* handle), but you're not allowed to have an unmanaged object directly, and the array of

Ambiguous function declaration in Javascript

会有一股神秘感。 提交于 2019-11-29 13:37:29
I am new to Javascript and got confused by how the function declaration works. I made some test on that and got some interesting results: say(); function say() { alert("say"); } The forward-declaration worked and popup "say" On the opposite say(); say = function() { alert("say"); } did not work, although it also declared a function object If we declare the function and redeclare that afterwards: function say() { alert("speak"); } say(); function say() { alert("say"); } I got "say" instead of "speak". That's surprise! OK. It seems that only the latest function declaration works. Then lets