typedef struct {
char name[10];
} A;
A * inst = get_instance_of_A();
char *str = g_strdup ( inst->name );
The last line doesn't compile. I also tried &(inst->name) with no luck.
The error I get is:
Error: char is not a structure type.
I understand that char[] and char * are different types altogether. But shouldn't g_strdup be able ...
Neither of these snippets of code work:
int main() {
struct mystruct {
int a;
char* b;
char* c;
} e,f;
e = {5, "blaat", "boe"};
return 0;
}
Error: syntax error for '{' token
int main() {
struct mystruct {
int a;
char* b;
char* c;
} e,f;
struct mystruct e...
A co-worker just created the following construction in C# (the example code is simplified). His goal was to shorten the notation for all predefined strings in the rest of the code.
public struct PredefinedStrings
{
public const string VeryLongName = "Very Long Name";
public const string AnotherVeryLongName = "Another Very Long N...
There doesn't seem to be any way as anonymous types derive from object. But I thought I'd ask since much of the time we use anonymous types in simple query expressions to extract subsets of data to be used in those anonymous types we create. It just seems to me they should be structs (value types) for greater memory efficiency vs. refere...
Consider this code block:
struct Animal
{
public string name = ""; // Error
public static int weight = 20; // OK
// initialize the non-static field here
public void FuncToInitializeName()
{
name = ""; // Now correct
}
}
Why can we initialize a static field inside...
I have a question. I have the following struct:
typedef struct{
int vin;
char* make;
char* model;
int year;
double fee;
}car;
Then I have the following method that asks the user for the make of a car and returns it as a char pointer
char* askMake(){
char* tempMake = NULL;
cout << "Enter Make:" << endl;
...
I have the following struct:
typedef struct{
int vin;
char* make;
char* model;
int year;
double fee;
}car;
Then I create a pointer of type car
car *tempCar;
How do I assign values to the tempCar? I'm having trouble
tempCar.vin = 1234;
tempCar.make = "GM";
tempCar.year = 1999;
...
I usually save serialized structs to my database, so
I pass them by reference a lot!
Is that a bad practice?
...
Hey,
Basically I've got some structs of type Ship which are going to go on a board which can have a variable width and height. The information about the ships is read in from a file, and I just need to know the best way to make sure that none of the ships overlap.
Here is the structure of Ship:
int x // x position of first part of shi...
this error stops compiling if i have one or more System.String in my structs
is there any other way to store strings?
i have tried things like this:
private long _B_ID;
private byte[] _C_Name;
private byte[] _C_Address;
private byte[] _C_Telephone;
but it is not seeming to work.
...
I'm trying to create an array of structs and also a pointer to that array. I don't know how large the array is going to be, so it should be dynamic. My struct would look something like this:
typedef struct _stats_t
{
int hours[24]; int numPostsInHour;
int days[7]; int numPostsInDay;
int weeks[20]; int numPostsInWeek;
int totNumLines...
I am struggling trying to come up with a clean way to redefine some register bitfields to be usable on a chip I am working with.
For example, this is what one of the CAN configuration registers is defined as:
extern volatile near unsigned char BRGCON1;
extern volatile near struct {
unsigned BRP0:1;
unsigned BRP1:1;
unsigned...
Can someone tell me why the commented line of code (one before last) does not compile? Isn't it the same as the line following it?
public struct OtherStruct
{
public int PublicProperty { get; set; }
public int PublicField;
public OtherStruct(int propertyValue, int fieldValue)
: this()
{
PublicProperty = ...
I am trying to make a program that works with poker (texas holdem) starting hands; each hand has a value from 1 to 169, and i want to be able to input each card and whether they are suited or not, and have those values correspond to a series of structs. Here is the code so far, i cant seem to get it to work (im a beginning programmer). ...
If one could put an array of pointers to child structs inside unsafe structs in C# like one could in C, constructing complex data structures without the overhead of having one object per node would be a lot easier and less of a time sink, as well as syntactically cleaner and much more readable.
Is there a deep architectural reason why ...
Hi.
I would like to know what do you use to sketch relations between different entities in C/C++. This can be a very broad issue, so I'll try to clarify a bit more my question and give an example.
I'm looking for something that is simple enough as a user, and let me sketch easily containers, pointers, etc... in an informal way.
The aim ...
Hello, I'm making a program in C, and I'mm having some troubles with memory, I think.
So my problem is: I have 2 functions that return a struct. When I run only one function at a time I have no problem whatsoever. But when I run one after the other I always get an error when writting to the second struct.
Function struct item* ReadFile...
Hi,
I'm trying to implement a simple priority queue from array of queues. I'm trying to define a struct queue, and than a struct priority queue that has an array of queues as its member variable. However, when I try to compile the code, I get the following error:
pcb.h:30: error: array type has incomplete element type
The code is bel...
Edit 2
Thanks for all the suggestions, I edited the code below from the suggestions given. However, it still doesnt seem to compile. But nevertheless, thanks a lot for the help hands.
Edit
I apologize for not putting the pcb struct into the code snippet. There is a struct called pcb defined in above the two structs I originally posted...
Here's what I take to be a pretty standard header for a list. Because the struct
points to itself, we need this two-part declaration. Call it listicle.h:
typedef struct _listicle listicle;
struct _listicle{
int i;
listicle *next;
};
I'm trying to get swig to wrap this, so that the Python user can make use of the listicle
...