I have a data structure like this:
struct foo {
int id;
int route;
... |
I'm using a struct like this:
define struct _Fragment{
int a;
char *seq;
}Fragment;
I want to initialize the struct, and using the malloc() method return ... |
I found some struct initialization code yesterday that threw me for a loop. Here's an example:
typedef struct { int first; int second; } TEST_STRUCT;
void testFunc() {
TEST_STRUCT ...
|
How can I initialize this nested struct in C?
typedef struct _s0 {
int size;
double * elems;
}StructInner ;
typedef struct _s1 {
StructInner a, b, c, ...
|
While reading a code I came across, the following definition and initialization of a struct:
// header file
struct foo{
char* name;
int value;
};
//Implementation file
struct foo fooElmnt __foo;
// some code using fooElmnt
struct foo fooElmnt __foo ...
|
What is the best way to accomplish the following in C?
#include <stdio.h>
struct A
{
int x;
};
struct A createA(int x)
{
struct A a;
a.x ...
|
How can I initialize a structure if one field in the structure is itself a structure?
Thank you.
|
|
I'm having difficulty initializing a struct in code per below. Can this even be done, or do I really need to memcpy (urg) the 5-character string into the struct?
struct MyStruct ...
|
I'm making a trie and I need someone to tell me what's wrong with this code:
typedef struct node
{
struct node *letters[26]={0};
} node;
I want to make it so that in every ... |
I seem to be having a problem setting the values of an array inside a structure with a meaningless error spat out of the compiler:
expected primary-expression before '{' ... |
I have a struct type as shown below:
typedef struct position{
float X;
float Y;
float Z;
float A;
} position;
typedef ...
|
I've run into a problem that seems to not be addressed by any of the C Standards after C89 save for the mention that structures initialization limits had been lifted. ... |
Does this snippet of code occur in a header file? If so, then TuBL is defined each time the header file is included. Is it possible that some other global symbol called TuBL exists somewhere else in your code? The other instance of TuBL might be a different type and be for a completely different purpose. It might even be a ... |
I am unable to understand why I am not able to initialize a global structure variable in the main function, while if I declare a local structure in the main function then I am able to initialize the variable. #include typedef struct abc { int a; int b; int c; } s1; s1 vin; void main () { vin = ... |
|
I have the following structs - 15 typedef struct pSimple { 16 char *key; 17 char *val; 18 } pSimple, *pSimple_ptr; 19 20 typedef struct pComplex { 21 char *name; 22 int value; 23 } pComplex, *pComplex_ptr; 24 25 typedef struct pNode { 26 char *nodeId; 27 struct pSimple *semStats; 28 struct pComplex *sysStats; 29 } pNode, *pNode_ptr; Now somewhere in ... |
I'm not sure if I can initialize members of a struct the lazy way. For example, let's say I have a struct defined as below: typedef struct _ABC { BOOL A; BOOL B; BOOL C; } ABC; If I want to initialize all members of the struct as false, is there a way of changing the state of the members all ... |
Bill Reid OK, let's say that have a function menu structure declaration like this (since I basically do): typedef struct function_item { char *descrip; void(*function)(void); } t_function_item; typedef struct function_menu { unsigned short num_items; unsigned short default_item; char *title_prompt; t_function_item *function_items; } t_function_menu; Now sometimes (really just about all the time) I want to initialize it to literal values. So this ... |
struct Point { int x; int y; }; Point Lines[3] = { {0,1}, {1,2}, {2,3} } The above works fine. What I'd like to do is declare Lines first and then populate the array later without having to individually add .x = and .y= for every attribute. Point Lines[3]; Lines[0] = {0,1}; This doesn't work. Is there someway to do that ... |
I suppose you can never know C++ fully. I would have never guessed this actually compiles and works: struct Point { int x, y; }; struct Line { Point endpoint[2]; int weight; }; Line createLine(int sx, int sy, int ex, int ey) { Line l = { sx, sy, ex, ey, 1 }; return l; } Both gcc and Visual Studio ... |
Recently I was pinged in a code review about my use of the initialization method AStruct myStruct = { 0 } ; Which initializes all elements of the myStruct to 0. I was questioned on it because no one had seen this construct. So i looked it up as best i could in the pointers to the Specification that I find ... |
|
Is this code, as the complete contents of a translation unit, valid C90 that initializes the struct foo to contain copies of the values passed to bar()? -------- struct foo { int i; void *v; }; int bar(int i,void *v) { struct foo f={i,v}; /*line 9*/ return f.i; } -------- GCC accepts it with -ansi, but complains about it with -ansi ... |
Hi people, I've got a question on global structure initialization. A global variable like int can be explicitly initialized as: int Global = 1; But how can I explicitly initialize a self-defined global structure? like: typedef mystruct { int a; int b; //... } Mystruct; I searched this group and heard that a global variable will be initialized to zero or ... |
Sheldon Hi, Can anyone help with this problem with setting up nested structures and initializing them for use. I have created several structs and placed them in a super struct that I will then pass to some functions. I have defined them in the following manner: typedef struct trans Transient; typedef struct sats Satellites; typedef struct data Data; typedef struct super ... |
|
Hello all! In my game, I have a structure defined as follows: typedef struct vegetation { vegetation_type type; bool harvested; int wood_yield; int fruit_content; int asciiChar; int color; char description[]; } vegetation; Later in the same header, I instantiate this type as follows: vegetation VEG_NONE = {VEG_TYPE_NONE,false,0,0,0,0,"None"}; This is obviously required, since the flexible array-member cannot be dynamically initialized. However, the ... |
Greetings, Can anyone, help me understand, why I am unable to intialize the structure as stated below? int normalArray[5] = {0x01, 0x02, 0x03, 0x04, 0x05}; typedef struct tag{ int value1; int value2; }myTypeStruct; myTypeStruct myStrVar[2] = { {normalArray[0], normalArray[1]}, {normalArray[2], normalArray[3]} }; The compiler throws me error, stating that 'the structure intialization requires a constant'. The same initialization works on the ... |
Hi all, I am new to C++ programming. Can some body explain how to intialize the structure values, consider this program, #include struct mystruct { int a,b,c,d,e,f; }; class myclass { mystruct x; public: myclass(){} void display(){ cout <<"Hi guys "; } }; int main() { myclass me; me.display(); } If you debug this program in gdb and stop it ... |
; 8 : struct foo bar = {1, 2, 3}; mov DWORD PTR _bar$[ebp], 1 mov DWORD PTR _bar$[ebp+4], 2 mov DWORD PTR _bar$[ebp+8], 3 ; 9 : struct foo baz; ; 10 : baz.a = 1; mov DWORD PTR _baz$[ebp], 1 ; 11 : baz.b = 2; mov DWORD PTR _baz$[ebp+4], 2 ; 12 : baz.c = 3; mov DWORD ... |
|
|
typedef struct { int nID; char ** pMessage; } MyStruct; MyStruct ** pSections[10]; int str[] = {0,1,10,88,1000,534,....}; for (i = 0; i < 10; i++) { pSections[i] = (MyStruct **) calloc(1, sizeof(MyStruct *)*str[i]); } for (i = 0; i<10; i++) { for (j = 0; j |
struct MyType { int x; int y; }; // data - if all members are static struct MyType initMyType = { 0, 0 }; // function - if some members are dynamic // like allocating space struct MyType initMyType ( void ) { struct MyType result; result.x = 0; result.y = 0; return result; } When you declare a variable, it ... |