struct

C语言关键---sizeof

[亡魂溺海] 提交于 2020-03-01 16:33:40
sizeof是C语言的一种单目操作符,如C语言的其他操作符++、--等。它并不是函数。sizeof操作符以字节形式给出了其操作数的存储大小。操作数可以是一个表达式或括在括号内的类型名。操作数的存储大小由操作数的类型决定。  二、sizeof的使用方法   1、用于数据类型    sizeof使用形式:sizeof(type)    数据类型必须用括号括住。如sizeof(int)。    2、用于变量    sizeof使用形式:sizeof(var_name)或sizeof var_name    变量名可以不用括号括住。如sizeof (var_name),sizeof var_name等都是正确形式。带括号的用法更普遍,大多数程序员采用这种形式。    注意:sizeof操作符不能用于函数类型,不完全类型或位字段。不完全类型指具有未知存储大小的数据类型,如未知存储大小的数组类型、未知内容的结构或联合类型、void类型等。    如sizeof(max)若此时变量max定义为int max(),sizeof(char_v) 若此时char_v定义为char char_v [MAX]且MAX未知,sizeof(void)都不是正确形式。  三、sizeof的结果   sizeof操作符的结果类型是size_t,它在头文件中typedef为unsigned int类型

How do you pass a typedef struct to a function?

坚强是说给别人听的谎言 提交于 2020-02-28 08:12:32
问题 At the moment I'm trying void avg(everything) But that gives me the error: error: subscripted value is neither array nor pointer And when I got this error earlier today it was because I wasn't passing a 2D array to the function properly. So I figure this is the same but I can't find the correct format to pass it in. This is my typedef: typedef struct structure { char names[13][9]; int scores[13][4]; float average[13]; char letter[13]; } stuff; And this is my typedef array: stuff everything[13

How do you pass a typedef struct to a function?

大兔子大兔子 提交于 2020-02-28 08:08:28
问题 At the moment I'm trying void avg(everything) But that gives me the error: error: subscripted value is neither array nor pointer And when I got this error earlier today it was because I wasn't passing a 2D array to the function properly. So I figure this is the same but I can't find the correct format to pass it in. This is my typedef: typedef struct structure { char names[13][9]; int scores[13][4]; float average[13]; char letter[13]; } stuff; And this is my typedef array: stuff everything[13

How to assign an array of structs

早过忘川 提交于 2020-02-25 13:15:30
问题 i have a function called create() that return a pointer to a struct named ann as shown below typedef struct ann { int inputs; /* Number of input neurones */ int hidden_layers; /* Number of hidden layers */ int hidden; /* Number of hidden neurones */ int outputs; /* Number of output neurons. */ int weights; /* Total nof weigths(chromosomes)*/ int neurons; /* Total Number of neurones */ double *weight; /* The weights(genotype) */ double *output; /* Output */ double fitness; /* Total fitness of

Unclear most vexing parse [duplicate]

一曲冷凌霜 提交于 2020-02-25 10:14:22
问题 This question already has answers here : Why does printing a function name returns a value? (3 answers) Closed 7 months ago . Let's assume the following class Foo. struct Foo { int i; }; if I want to make an instance of this class and initialize it, I should do: Foo foo1 = Foo(); to call the constructor. int main(void) { foo1 = Foo(); cout << foo1.i << " : " << foo1.j << endl; // " 0 " } then I thought I'd call the default constructor with the following line but it doesn't: int main(void) {

Unclear most vexing parse [duplicate]

半城伤御伤魂 提交于 2020-02-25 10:14:09
问题 This question already has answers here : Why does printing a function name returns a value? (3 answers) Closed 7 months ago . Let's assume the following class Foo. struct Foo { int i; }; if I want to make an instance of this class and initialize it, I should do: Foo foo1 = Foo(); to call the constructor. int main(void) { foo1 = Foo(); cout << foo1.i << " : " << foo1.j << endl; // " 0 " } then I thought I'd call the default constructor with the following line but it doesn't: int main(void) {

Sorting function for a vector of objects based on different fields

最后都变了- 提交于 2020-02-25 04:41:47
问题 I have a vector of objects: struct Student{ string name; string id; string major; int age; }; vector<Student> s; Is there any way to write ONE general (maybe template) function to sort this vector (or array) based on different fields instead of writing four different functions? 回答1: I think the previous comments all said that it is possible to write such a comparison function. But if I understand you correctly, you want one function for all 4 comparisons (maybe in a templated way). There is

Why is this struct not standard-layout?

此生再无相见时 提交于 2020-02-23 11:33:32
问题 A piece of code is worth a thousands words. #include <iostream> #include <type_traits> using namespace std; struct A { int a; }; struct B : A { int b; }; int main() { cout << is_standard_layout<B>::value << endl; // output false! WHY? return 0; } 回答1: From the definition of standard layout classes (§9 Classes, paragraph 7) [...] * either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data

Why is this struct not standard-layout?

我的梦境 提交于 2020-02-23 11:33:24
问题 A piece of code is worth a thousands words. #include <iostream> #include <type_traits> using namespace std; struct A { int a; }; struct B : A { int b; }; int main() { cout << is_standard_layout<B>::value << endl; // output false! WHY? return 0; } 回答1: From the definition of standard layout classes (§9 Classes, paragraph 7) [...] * either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data

Second order functions in GLSL?

巧了我就是萌 提交于 2020-02-21 12:35:28
问题 I'm looking for a way to use a function as an argument to another function in GLSL. In regular C, it can be simulated by passing a function pointer as a function argument. It also seems that other languages (like HLSL) now provide ways to deal with high-level constructs like higher-order functions, or can simulate them with clever use of HLSL structures. unfortunately I'm stuck with GLSL for now, and I can't find any way to simulate higher-order functions. Is it really impossible in current