struct

Structure have objects and cannot be copied

心不动则不痛 提交于 2019-12-24 02:24:22
问题 I'm trying to start with my first MQL4 expert advisor, I've created a struct to handle my orders: struct Order { int pair; int command; double quantity; double entry; double stopLoss; double profit; int slippage; string comment; int magicNumber; datetime expire; }; but it seems I can't do this: Order a; Order b=a; the compiler hangs saying: '=' - structure have objects and cannot be copied How can I assign a struct ? 回答1: As MQL4 documentation says: Structures that do not contain strings or

struct - sorting a c-string with qsort

↘锁芯ラ 提交于 2019-12-24 02:23:27
问题 I'm sorting a bunch of IPs, but for some reason they come in the wrong order. I'm not quite sure where could be the problem. 66.249.71.3 190.148.164.245 207.46.232.182 190.148.164.245 190.148.164.245 202.154.114.253 190.148.164.245 190.148.164.245 66.249.71.3 190.148.164.245 202.154.114.253 Here it is the way Im sorting them. typedef struct { char *ip; } mystruct; /* qsort */ int struct_cmp(const void *a, const void *b) { mystruct *ia = (mystruct *)a; mystruct *ib = (mystruct *)b; return

Pointer to array of struct in function

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:21:12
问题 I had a problem with the pointers. I wanna read a binary file with a function, and then, use the read data in the main. The problem is that I had to pass a pointer to array of struct to can use the data in main. The code is: #define TMOLDEO 8 #define TAM 41 struct fichpiezas{ int codPieza; float dimPieza; float costePieza[TMOLDEO]; }; int leer_fichero(struct fichpiezas *vpiezas[]); int main(int argc, const char * argv[]) { struct fichpiezas vpiezas[TAM]; leer_fichero(&vpiezas); for(int i = 0;

.NET behaviour of LayoutKind.explicit for a field which is itself a struct

寵の児 提交于 2019-12-24 02:17:05
问题 Question I tried building a struct ( SA ) using [StructLayout(LayoutKind.Explicit)] , which had a field which is another struct ( SB ). First : I was surprised I was allowed to declare that other struct without [StructLayout(LayoutKind.Explicit)] , whereas in SA , all fields must have [FieldOffset(0)] , or the compiler will shout. It doesn't make much sense. Is this a loophole in the compiler's warnings/errors ? Second : it seems that all reference ( object ) fields in SB are moved to the

typedef and struct namespaces in C vs C++

…衆ロ難τιáo~ 提交于 2019-12-24 02:16:31
问题 I am trying to use some old C libraries in some new C++. The library's header files use D. Hanson's "C Interfaces and Implementations" implementation-hiding idiom of: #define T MyAST typedef struct T *T; Near as I can tell, this compiles with C because in C struct names and typedef names are in different namespaces but it does not compile with C++ ( extern "C" { #include "MyAST.h" } ) evidently because typedef and struct names are in the same namespace. conflicting declaration 'typedef struct

How to read struct field ` ` decorators?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:57:28
问题 My package needs to be able to let my users define the fields backend database column name explicitly, if they want to. By default I will use the fields name - but sometimes they will need to manually specify the column name, just like the JSON package - unmarshal uses the explicit name if required. How can I consume this explicit value in my code? I don't even know what it's called so Google is really failing me at the moment. Here's what JSON's unmarshal function needs for example: type

Looping through elements in a struct in C for extracting value and datatype of the individual element

元气小坏坏 提交于 2019-12-24 01:49:20
问题 I have a requirement where I have a big structure in C consisting of around more than 30 different elements of different data types: typedef struct { type1 element1; type2 element2; type3 element3; type2 element4[10]; ... typeN elementN; } my_messg_struct; where this is basically a group of elements in a message sent over the serial protocol. This message has various elements of varying datatypes as captured in the above structure. Similarly, I have a lot of other messages as well. Now I have

Why is it valid to define a type as pointer to an undefined struct in C?

谁说胖子不能爱 提交于 2019-12-24 00:39:17
问题 I was digging into a 3rd party code base and found that it is apparently valid to declare a type as a pointer to an undefined struct. As a minimum working example, consider a C file test.c containing nothing but: typedef struct foo *bar; What surprises me is that this file compiles without any problems using the command gcc test.c -shared Why does the compiler not complain about the struct foo not being declared anywhere? My environment is Ubuntu 16.04 with gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5)

C/C++ Struct memory layout equivalency

↘锁芯ラ 提交于 2019-12-24 00:23:49
问题 Consider the following C struct and C++ struct declarations: extern "C" { // if this matters typedef struct Rect1 { int x, y; int w, h; } Rect1; } struct Vector { int x; int y; } struct Rect2 { Vector pos; Vector size; } Are the memory layouts of Rect1 and Rect2 objects always identical? Specifically, can I safely reinterpret_cast from Rect2* to Rect1* and assume that all four int values in the Rect2 object are matched one on one to the four int s in Rect1 ? Does it make a difference if I

How to correctly and safely free() all memory used a nested struct in C?

余生颓废 提交于 2019-12-23 23:51:08
问题 I have four different layers of struct nested. The code is as follows: typedef struct System system; typedef struct College college; typedef struct Student student; typedef struct Family family; #define MAX_COLLEGES 10 #define MAX_NAME_LEN 32 #define MAX_STUDENTS 10 struct System { college *Colleges[MAX_COLLEGES]; }; struct College { char name[MAX_NAME_LEN]; student *Students[MAX_STUDENTS]; }; struct Student { char name[MAX_NAME_LEN]; int id; family *fam; //was typo familiy }; struct Family {