struct

Structure and tagged union in c

独自空忆成欢 提交于 2020-01-06 15:32:09
问题 #define HOST_NAME "UDP" #define ADDRESS "127.0.0.1" struct UDP_IP_Parameters { uint version; /* e.g. "1.0" = 0x0100 */ uint port; /* PORT */ taggedunion { "HOST_NAME" char[256]; "ADDRESS" char[15]; }; }; int main() { struct UDP_IP_Parameters udp; udp.version = 0x0100; udp.port = 444; } I have created a structure and taggedunion nested within that. Is it possible to define the host name and address as constant like above ?? Is it possible to assign some values by creating a objects for it.

Enumerating generic structs

这一生的挚爱 提交于 2020-01-06 15:16:22
问题 I wanted to try to build a proper implementation of Peano numbers using struct s, but it seems my generics game is not good enough yet and I could use some help. I read the docs on generics and some StackOverflow questions, but they don't fit my case. I introduced a Peano trait and Zero and Succ types: trait Peano {} struct Zero; struct Succ<T: Peano>(T); And implemented a Peano trait for both types to be able to abstract over both: impl Peano for Zero {} impl<T> Peano for Succ<T> where T:

allocating flexible array members as a struct

我们两清 提交于 2020-01-06 08:47:50
问题 I understand more about pointers and stuff but I have no idea what I am doing wrong here. if i Have char *(*data)[] That would just be interpreted as "a pointer to an array of char pointers", right? Then I have a struct like this, typedef'd to be myStruct, redundant as it may be, but that's aside the point: typedef struct myStruct myStruct; struct myStruct{ int size; char *name; myStruct *(*array)[]; } Having looked around the site for similar posts, I got something like this: //let's say

Struct Alignment with PyOpenCL

狂风中的少年 提交于 2020-01-06 08:13:24
问题 update: the int4 in my kernel was wrong. I am using pyopencl but am unable to get struct alignment to work correctly. In the code below, which calls the kernel twice, the b value is returned correctly (as 1), but the c value has some "random" value. In other words: I am trying to read two members of a struct. I can read the first but not the second. Why? The same issue occurs whether I use numpy structured arrays or pack with struct. And the _-attribute__ settings in the comments don't help

Getting a value from a Struct Array ARDUINO

允我心安 提交于 2020-01-06 05:46:26
问题 I am having an issue retrieving the values stored in a Struct and have no idea why. I am working on the Arduino IDE 1.8.7 In h file // structure to hold each "display unit" settings typedef struct { int displayState; int pixelState[]; int startLed; // the first LED number EG: 8 if the previous display used 0-7 int endLed; int brightness; int saturation; } struct_displayType;` In setup // display[0] is all leds displayUnit[0].displayState=5; displayUnit[0].brightness=255; displayUnit[0]

Cast json that contains interface in properly struct

眉间皱痕 提交于 2020-01-06 05:36:14
问题 i'm unable to cast the following json in a struct in Golang, received from Kraken API: { "error": [], "result": { "LINKUSD": { "asks": [ ["2.049720", "183.556", 1576323009], ["2.049750", "555.125", 1576323009], ["2.049760", "393.580", 1576323008], ["2.049980", "206.514", 1576322995] ], "bids": [ ["2.043800", "20.691", 1576322350], ["2.039080", "755.396", 1576323007], ["2.036960", "214.621", 1576323006], ["2.036930", "700.792", 1576322987] ] } } } Using json-to-go , he gives me the following

Getting a segmentation fault while trying to write a struct instance to a file

纵然是瞬间 提交于 2020-01-06 03:29:45
问题 I am trying to write a struct to a file, but am getting a segmentation fault at run time: #include<stdio.h> //just a struct for purposes of demonstration struct my_struct{ int prop1; int prop2; }; //writes dummy struct to filename.dat void writeStruct(){ FILE *file_pointer; file_pointer = fopen("filename.dat","w"); //define and assign variables to a quick dummy struct struct my_struct *this_struct; this_struct->prop1=0; //seg faults here! this_struct->prop2=1; //write struct to file fwrite

Converting a sniffed scapy packet to bytes

与世无争的帅哥 提交于 2020-01-06 02:54:11
问题 When sniffing packets with scapy I can save them to a variable sniffed = sniff(count=1) Now I would like to see what's inside the packet by doing print sniffed or print str(sniffed) but all this gives me is something like the following: ������0� E4h@@����������� l�� which isn't quite what I need. So how can I convert a sniffed packet into human readable Binary, or an array of Bytes or something more useful so that I can see what's inside? I have already tried using struct.unpack(format,

sort list of struct of different types in net 2.0

妖精的绣舞 提交于 2020-01-06 02:47:32
问题 Does anyone know how to sort a list of struct with different types (sample code below)? We are currently using Net 2.0, so we cannot use Linq. Thanks in advance! public struct dataKeys { private long key1; private long key2; private string key3; public long Key1; { get { return key1;} set { key1 = value; } } public long Key2; { get { return key2;} set { key2 = value; } } public string Key3; { get { return key3;} set { key3 = value; } } } . . . List<dataKeys> dataKeyList = new List<dataKeys>()

GCC -Wuninitialized not warning about uninitialized structs

守給你的承諾、 提交于 2020-01-06 02:14:17
问题 #include <ctime> #include <iostream> #include <cstring> int main() { struct tm tm ; //memset(&tm, 0, sizeof(struct tm)); strptime("1 Jan 2000 13:00:00", "%d %b %Y %H:%M:%S", &tm); time_t t =mktime(&tm); std::cout << ctime(&t); return 0; } g++ -Wuninitialized -O2 test.cpp doesn't warn about tm not having been initialized. Valgrind does until the memset line is added. the Man pages for strptime on Linux say it should be initialised and I was seeing randomized dates on a more complicated program