Pointers to other structures in a structure

My lecturer has presented the following piece of code, with an insufficient explanation of what it represents. typedef struct _s { int value; struct _s *next; } STACKITEM; STACKITEM *stack = NULL; I understand what pointers and structures are. Howeve

Knowing if a variable is an instance of a class or structure

There is a way to know if a variable in swift is an instance of a class or a struct? I'm trying to do a deepCopy but I'm only interested in doing that if it is an instance of a class, not a structI found a way to do this func getDeepCopy<T>(object:

If the statement in the linked list does not work as expected

So currently i have an if statement in the GetNth function that im trying to test. but when i inserted a printf function, it made me notice that it goes through the if statement even if the condition is not met, however, when i remove the printf stat

How to check if a structure has a certain variable?

So I have the following two structs. Let's say I have a void pointer that, depending on the situation, will point to either bag or apple. How do I check which struct type it is pointing to so I can dereference it? struct product { int price; string n

Initialization of an atomic flag in a mallocalised structure

I'm trying to use atomics in C on FreeBSD 10.1 Release with clang 3.6.1, however when I try to compile a program using ATOMIC_FLAG_INIT on a atomic_flag variable in a struct I get error: expected expression. Here is the program I am trying to compile

c ++ - struct and class stuffing

I always pad my structs in C to get the maximum performance (good memory alignment). // on a x86_64 struct A { int64_t z; int32_t x; int16_t y; // we don't care the uint8_t position, as they are 1 byte wide. uint8_t s[8]; uint8_t t[4]; } But if I dec

Problem with structures and strings

I made a linked list whose nodes hold 4 string values. When I call the newNode function, an error says 'Node has no member named familyName', as well as the other members. My code: I am really confused with how strings work in structs.Your immediate

conformable variable length structure in C ++

In standard C you can end a struct with an array of size 0 and then over allocate it to add a variable length dimension to the array: struct var { int a; int b[]; } struct var * x=malloc(sizeof(var+27*sizeof(int))); How can you do that in C++ in a st

Create a struct parameter

I have a struct defined as : typedef struct pt { int x; int y; }point; I also have a stack push function declared as : void push(point p); Now whenever i wish to call this function, I can do the following : point p = {x_value, y_value}; push(p); I wa

Why free (): invalid next size (fast)

Please, see the c-code and help me. Why i have "free(): invalid next size (fast)" ? I try valgrind, but don't understand, there are too much "invalid write/read ....", but if I comment free_array(all) a have right answers. It's just a

Dynamic allocation of C structures

I have a problem with dynamic memory allocation. Here is the code so please help. #include <stdio.h> int i; typedef struct{ int A; }node; typedef struct Model { node *m; } Model; Model M; void initialize(Model *a, int size) { a->m = (node*) mallo

get a primitive from a structure based on this index

Ive got the following typedef struct{ GLfloat x; GLfloat y; GLfloat z; }Vertex3D; and I want to use a for loop. is it possible to specify which primitive you want from a struct based on its index. e.g if I wanted using the number 0 for x 1 for y and

Constructors for structures that do nothing

Edit: Just to be clear, the struct doesn't do anything, as in it has no functions. I think I gave the impression that I thought using an initialiser list and leaving the body of the constructor empty was the issue at hand. Say I'm using a struct to h

How can I make this instance of structure volatile in C?

I'm using a generic buffer .c/.h file. I want to create an instance that is qualified as volatile to use as a com buffer. The following code shows the problem, the qualifier is lost?? when passing the buffer address to the member functions. The code

in clojure - How to use a list item one by one?

i'm using a StructMap in Clojure, and trying to add map using struct by a list of values. currently my struct includes only 3 keys, so i'm using the following to add new struct: (struct user-struct (first list-vals) (second list-vals) (nth list-vals

Create a std list :: template structures (C ++)

I have a struct defined as follows: template <typename T> struct data { int num; T *ptr; }; I want to create a std::list of various data structs using different types like: struct data<My_Favorite_Type> a; struct data<My_Second_Favorite_Typ

Initializing tables in C with void *

Say I have a group of struct's that I want to manage arrays of via blocks of pointers. I would like to initialize these blocks in a generic fashion, and here's what I'm thinking: enum my_type {STRUCT_1, STRUCT_2, STRUCT_3} ; struct my_struct_1 {...}

How to add new members to Struct

These are functions and Struct declarations I have, and I'm not allowed to change them. DerivedA giveDerivedA (); DerivedB giveDerivedB (); struct Base{ QString elementId; QString elementType; }; struct DerivedA : Base { int a; int b; }; struct Deriv