struct

C How to manage #include relationship among multiple source files and create correct makefile

谁都会走 提交于 2020-01-16 19:29:40
问题 I again re-edited my question and this time it is final. note: the program is working (thanks for all the help). But I still have some confusion about how the dependency/linkage actually works. Specifically I would like to be walked through the process that the makefile compiles and runs. (example, the compiler first looks at main.c, starting from line 1, which is main.h, goes into main.h, starting from line 1, which points to function1.h, and so on.) My main question here is though: is it

Declaring a 2D array of type struct in c++ [closed]

落爺英雄遲暮 提交于 2020-01-16 14:45:15
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I declared a struct which is supposed to be a pixel and it has 3 properties ( x , y location and F intensity) like this: struct pixel { int F, // intensity from 0-255 x, // horizontal component y; // vertical

Struct received over COM port from Arduino has incorrect values in some but not all of its fields

我怕爱的太早我们不能终老 提交于 2020-01-16 11:27:28
问题 I want to send some serial values to my PC. Arduino with sensors (master) >> via Bluetooth >> Arduino (slave) >> via serial com port >> PC with C# app Serial transmission works well from master to slave, but how can I receive and convert the values received to floats on the PC side using C#? Slave code is: Struct definition typedef struct { char bt1; float bt2; float bt3; float bt4; float bt5; float bt6; float bt7; char bt8; } PayloadBT; PayloadBT payloadBT; Struct sent to pc BT_writeAnything

Proper way of accessing field of a 1xn stuct

我们两清 提交于 2020-01-15 12:15:21
问题 I have looked for the proper way to access a given field of a struct and the manual and online searches didn't help. Formally, let MyStruct be a 1xn struct variable. It's easy to list all the elements stored in a field with: MyStruct.Thisfield ans = 0.7010 ans = 0.310 ans = 0.444 etc. Now the only way I found to be able to access an element of this is to use a temporary variable, e.g. temp={MyStruct.Thisfield} and then temp{1,2} etc. I think it's clumsy but can't figure out what else to do.

Unmarshal a YAML to a struct with unexpected fields in Go

岁酱吖の 提交于 2020-01-15 12:11:23
问题 I encountered an issue while trying to unmarshal a struct with an unexported field using github.com/go-yaml/yaml . The struct looks like: type Example struct { ExportedField string `yaml:"exported-field"` OneMoreExported string `yaml:"one-more-exported"` unexportedField map[string]*AnotherExample `yaml:"unexported-field"` } type AnotherExample struct { Name string `yaml:"name"` } And I'd like to unmarshal such YAML as exported-field: lorem ipsum one-more-exported: dolor set unexported-field:

Unmarshal a YAML to a struct with unexpected fields in Go

走远了吗. 提交于 2020-01-15 12:09:20
问题 I encountered an issue while trying to unmarshal a struct with an unexported field using github.com/go-yaml/yaml . The struct looks like: type Example struct { ExportedField string `yaml:"exported-field"` OneMoreExported string `yaml:"one-more-exported"` unexportedField map[string]*AnotherExample `yaml:"unexported-field"` } type AnotherExample struct { Name string `yaml:"name"` } And I'd like to unmarshal such YAML as exported-field: lorem ipsum one-more-exported: dolor set unexported-field:

double pointer to struct inside struct

本秂侑毒 提交于 2020-01-15 11:45:08
问题 How can i access to a duble pointer in a struct pointer?? with the code bellow, calling addBow() give me a Segmentation fault (core dumped) error typedef struct { int size; tCity **cities; }tGraph; //para iniciar el grafo void initGraph(tGraph *graph, int size) { graph = (tGraph*)malloc(sizeof(tGraph)); graph->cities = (tCity**)malloc(sizeof(tCity*) * size); graph->size = size; } //agrega un arco entre ciudades void addBow(tGraph *graph, int id, tCity *city) { if ( graph->cities[id] == NULL )

Getting negative value with bit-fields

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 11:17:31
问题 I have a question related to bit-fields in C. Here I have such a structure: struct Register { int bit:1; }; int main(void) { struct Register bit = {1}; printf("\nbit = %d", bit.bit); return 0; } Can you please explain me why do I get: bit = -1 回答1: If you're working with bitfields, you should use unsigned int . signed int is a problem for bit-fields. 回答2: use unsigned int , it stores 0 and 1, struct Register { unsigned int bit:1; }; int main(void) { struct Register bit = {1}; printf("\nbit =

Struct layout in apcs-gnu ABI

感情迁移 提交于 2020-01-15 10:35:06
问题 For this code: struct S { unsigned char ch[2]; }; int main(void) { _Static_assert( sizeof(struct S) == 2, "size was not 2"); } using GCC (various versions) for ARM with the ABI apcs-gnu (aka. OABI, or EABI version 0), I get the assertion fails. It turns out the size of the struct is 4 . I can work around this by using __attribute__((packed)) ; but my questions are: What is the rationale for making this struct size 4 ? Is there any documentation specifying the layout of structs in this ABI? On

Getting data from pointer in struct “Invalid read/write”

偶尔善良 提交于 2020-01-15 10:03:56
问题 I am trying to do a implementation of circular buffer in array. I keep my data in structure and manage it by few methods as push, pop, etc. The program is more or less functional and behave as expected, however I run into errors in my valgrind test. And I am not capable of finding out what is wrong with my code. Although it seems like managing data via pointers in my struct is the crucial problem. I would be very grateful if anyone could point me in the right direction coz I am really lost at