declaration

Differences between pointer declaration [duplicate]

╄→гoц情女王★ 提交于 2021-02-05 12:29:55
问题 This question already has an answer here : Difference between char* var; and char *var;? [duplicate] (1 answer) Closed 7 years ago . Is there any differences between these two declarations? int* a; int *a; Or these two declarations are the same (pointer to an integer)? 回答1: They're exactly the same, but here's a small gotcha I came across when first learning C years ago. The * binds to the variable , not the type. This means that int* a, b; Declares a as a pointer to int, and b as an int . To

Can array length in declaration be non-constant?

夙愿已清 提交于 2021-02-05 08:41:09
问题 I am a bit confused about array declaration in C. I know that it's possible to do this: int a[20]; // Reserved space for 20 int array int b[] = {32, 431, 10, 42}; // Length in square brackets is auto-calculated int *c = calloc(15, sizeof(int)); // Created a pointer to the dynamic int array But is it possible to do this?: int my_array[sizeof(int) * 5]; Is it a valid code, or an array length should be a constant expression (in ANSI C)? 回答1: sizeof(int) * 5 used in the example statement in your

Can array length in declaration be non-constant?

那年仲夏 提交于 2021-02-05 08:40:38
问题 I am a bit confused about array declaration in C. I know that it's possible to do this: int a[20]; // Reserved space for 20 int array int b[] = {32, 431, 10, 42}; // Length in square brackets is auto-calculated int *c = calloc(15, sizeof(int)); // Created a pointer to the dynamic int array But is it possible to do this?: int my_array[sizeof(int) * 5]; Is it a valid code, or an array length should be a constant expression (in ANSI C)? 回答1: sizeof(int) * 5 used in the example statement in your

Platform specific macros in OpenGL headers

和自甴很熟 提交于 2021-02-04 20:49:27
问题 I was parsing gl.h and I noticed a quite unusual (at least to me) way of declaring openGL functions. Here is an example: GLAPI void APIENTRY glEvalCoord1d( GLdouble u ); GLAPI void APIENTRY glEvalCoord1f( GLfloat u ); GLAPI void APIENTRY glEvalCoord1dv( const GLdouble *u ); Obviously, those are regular functions with return type void, but my questions is about the effect of GLAPI and APIENTRY macros. Those two are platform specific, declared in the beginning of the header: /* GLAPI, part 1

How to decipher complex pointer declarations in C?

六月ゝ 毕业季﹏ 提交于 2021-02-04 12:26:39
问题 So I want to give an example: int *pi; // pi is a pointer that points to an integer const int *cpi; // cpi is a pointer that points to a constant integer char *pc; // pc is a pointer to a char How can I read these: char **x; //x is a pointer to a char pointer? char *y[]; char **z[]; Thanks. 回答1: cdecl.org is often linked to such questions. No doubt that it make easier to decipher any complex declaration, but at the same time it just provide an abstracted information. Being a C or C++

Template friend function of template class

♀尐吖头ヾ 提交于 2021-01-28 05:51:29
问题 I am wondering how to make a function friend of a class and define the function outside class if the function's template arguments include but are not limited to the class's template arguments. For example, I have the following template class and template friend function: template<int N> class Matrix; template<typename T, int N> Matrix<N> operator*(const Matrix<N> &m1, const T &m2); // class definition template<int N> class Matrix{ template<typename T> friend Matrix<N> operator* (const Matrix

Global object declaration in kotlin

夙愿已清 提交于 2021-01-27 04:39:11
问题 How to declare objects globally in kotlin like in java TextView tv; . Or any method to call the same variable in different methods/functions. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView: TextView = findViewById(R.id.texfirst) as TextView textView.setOnClickListener { Toast.makeText(applicationContext,"Welcome to Kotlin ! $abc "+textView.text, Toast.LENGTH_LONG).show() } myFunction(textView) } fun

error: “initializer expression list treated as compound expression”

空扰寡人 提交于 2020-12-30 09:35:08
问题 I'm having an issue compiling the beginnings of a basic password protected file program, I'm getting the above error on line 11, (int login(username,password)). Not sure what's going on here, so it'd be nice if someone could shed some light on the situation. #include <iostream> #include <conio.h> #include <string> using namespace std; int i,passcount,asterisks; char replace, value, newchar; string username,password,storedUsername,storedPassword; int login(username,password); { if (username=

Template class type alias failing substitution in member declaration

假如想象 提交于 2020-12-06 04:41:42
问题 Assume you have a templated class like this: template <typename type> class Object { using length_t = unsigned int; template <length_t length> void put(type (&)[length]); }; and you declared a put(...) method in it like so. How do you go about declaring that put(...) method outside the class ? Here's one approach someone might take: /* ERROR: Doesn't match any declarations(?) */ template <typename type> template <typename Object<type>::length_t length> void Object<type>::put(type (&)[length])

Why is creating a variable using 'extern' a declaration and not a definition?

走远了吗. 提交于 2020-11-29 09:22:30
问题 I came across the following problem while reading ...just cant get the logic behind this. auto int c; static int c; register int c; extern int c; It is given that the first three are definition and last one is declaration ..how come ? 回答1: The last one with extern does not define storage for c . It merely indicates that c exists somewhere and the linker should be able to resolve it to some global c defined elsewhere. If you compiled and linked a single .c file and tried to use the last c you