Tags "struct" Result

struct in struct

Hello. My compiler (GCC 3.3.*) does not complain about the following: #include <iostream> #include <vector> using namespace std; struct X{ int a,b,c; vector<X> pp; }; int main(){ X a; } So there is not a problem with this self-refering struct, why? Must not vector know the size of what it should contain? Solution On Mon, 31 May

it1352 1 2019-06-25

Struct inside struct

I must create a Person and each Person should have a Fridge. Is this the best way of doing it? If so what am I doing wrong? Thanks in advance. typedef struct { int age; struct FRIDGE fridge; } PERSON; typedef struct { int number; } FRIDGE; FRIDGE fr; fr.number=1; PERSON me; me.name=1; me.fridge = fr; This gives me the following error:

it1352 0 2019-05-14

creating struct within struct

I'm working on importing an old C windows driver project that was created in Visual c 6.0 into visual studio 2012. The way that the structs were defined are causing errors in vs2012. typedef struct { LINK Link; HANDLE hFile; BYTE handleType; OVERLAPPED Overlapped; CRITICAL_SECTI

it1352 0 2019-05-13

Defining struct within typedef struct

typedef struct leaf{ int value; struct leaf* lchild; struct leaf* rchild; } LEAF; For example the one above defines structure leaf and makes 2 members of that type: lchild, rchild. So is this like a recursion? Solution Your assumption is wrong. leaf has 2 members of type leaf*, not leaf. So it's not (data) recursion. And the following s

it1352 2 2019-05-13

Assign struct with another struct

I have a RegistrationRequest struct: type RegistrationRequest struct { Email *string Email2 *string Username *string Password *string Name string } Where Email2 is the email value entered again to verify that what the user entered is correct. I also have a User struct: type User struct { Email *strin

it1352 1 2019-05-18

struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct));

What is wrong with the above? Don''t worry, I already know (learned my lesson last week.) It is for the benefit of our resident compiler guru who seems to think you need the cast. I thought it too, up until I started posting here! Thanks, Chris Solution "Chris Fogelklou" <ch*************@comhem.se> wrote in message news:7l*****

it1352 0 2019-06-25

Copy struct to struct in C

I want to copy an identical struct into another and later on use it as a comparance to the first one. The thing is that my compiler gives me a warning when Im doing like this! Should I do it in another way or am I doing this wrong: In header File: extern struct RTCclk { uint8_t second; uint8_t minute; uint8_t hour; uint8_t mday; uint8_t month; ui

it1352 1 2019-05-09

Typedef struct vs struct? |Definition difference|

The following blocks are outside of main() and before every function (global scope) 1st block: struct flight{ int number; int capacity; int passengers; }; With this you can create array,pointer,variable in contrast with writing }var; (which defines only one variable of this custom data type (struct flight)) 2nd block: typedef struct flight{ in

it1352 1 2020-07-21

volatile struct = struct not possible, why?

struct FOO{ int a; int b; int c; }; volatile struct FOO foo; int main(void) { foo.a = 10; foo.b = 10; foo.c = 10; struct FOO test = foo; return 0; } This won't compile, because struct FOO test = foo; generates an error: error: binding reference of type 'const FOO&' to 'volatile FOO' discards qualifier

it1352 0 2020-09-27

Golang : anonymous struct and empty struct

http://play.golang.org/p/vhaKi5uVmm package main import "fmt" var battle = make(chan string) func warrior(name string, done chan struct{}) { select { case opponent := <-battle: fmt.Printf("%s beat %s\n", name, opponent) case battle <- name: // I lost :-( } done <- struct{}{} } func main() { done

it1352 3 2019-05-14