struct

Struct inheritance in MIDL

I am trying to inherit from and extend a structure defined in MIDL. I used the same syntax as for interface inheritance i.e typedef struct stDBIBinVarDataEx { float x; } MYSTRUCT ; struct struct2 : MYSTRUCT { float y; }; but the compiler generates errors. ...

c++ stl priority queue insert bad_alloc exception

Hi, I am working on a query processor that reads in long lists of document id's from memory and looks for matching id's. When it finds one, it creates a DOC struct containing the docid (an int) and the document's rank (a double) and pushes it on to a priority queue. My problem is that when the word(s) searched for has a long list, when ...

Imitate database in C

I am fairly new to C. (I have good knowledge of C# [Visual Studio] and Java [Eclipse]) I want to make a program that stores information. My first instinct was to use a database like SQL Server. But I don't think that it is compatible with C. So now I have two options: Create a struct (also typedef) containing the data types. Find a way...

Accessing any structs members at run-time.

Is it possible to get access to an individual member of a struct or class without knowing the names of its member variables? I would like to do an "offsetof(struct, tyname)" without having the struct name or member variable name hard coded amoungst other things. thanks. ...

passing structure directly to function

I have a struct that I initialize like this: typedef struct { word w; long v; } MyStruct; MyStruct sx = {0,0}; Update(sx); Now, it seems such a waste to first declare it and then to pass it. I know that in C#, there's a way to do everything in one line. Is there any possiblity of passing it in a more clever (read: cleaner) way to ...

Why should structure names have a typedef?

I have seen source codes always having a typedef for a structure and using the same everywhere instead of using the structure name as "struct sname" etc directly? What is the reason behind this? Are there any advantages in doing this? ...

Is it possible to override Value on a nullable struct, to return a diffrent type?

This might sound crazy to you, but I need a Nullable<T> (where T is a struct) to return a different type for it's Value property. Rules being if Nullable<T>'s Property HasValue is true, Value will always return an object of a different specified type (then itself). I might be over thinking this, but this unit test bellow kind of shows ...

Why Can I Change Struct's int[] Property from Method Without Specifying "ref"?

From a method, I can pass a struct which contains an array of integers, and change the values in the array. I am not sure I understand fully why I can do this. Can someone please explain why I can change the values stored in the int[]? private void DoIt(){ SearchInfo a = new SearchInfo(); a.Index = 1; a.Map ...

struct.error: unpack requires a string argument of length 4

Python says I need 4 bytes for a format code of "BH": struct.error: unpack requires a string argument of length 4 Here is the code, I am putting in 3 bytes as I think is needed: major, minor = struct.unpack("BH", self.fp.read(3)) "B" Unsigned char (1 byte) + "H" Unsigned short (2 bytes) = 3 bytes (!?) struct.calcsize("BH") says 4 ...

When to use a namespace or a struct?

I was just reading a little bit on them from http://www.cplusplus.com/doc/tutorial/namespaces/ and it seems like a struct is capable of the same things? Or even a class for that matter. Maybe someone here can better define what a namespace is, and how it differs from a struct/class? ...

Port C's fread(&struct,....) to Python

Hey, I'm really struggling with this one. I'am trying to port a small piece of someone else's code to Python and this is what I have: typedef struct { uint8_t Y[LUMA_HEIGHT][LUMA_WIDTH]; uint8_t Cb[CHROMA_HEIGHT][CHROMA_WIDTH]; uint8_t Cr[CHROMA_HEIGHT][CHROMA_WIDTH]; } __attribute__((__packed__)) frame_t; frame_t frame; while ...

Pass struct as id possible?

I would like to execute a function which obtains a struct in an separate Thread but not sure how to pass the struct right. Having this: - (void) workOnSomeData:(struct MyData *)data; How to properly call: struct MyData data = ... ; [[[NSThread alloc] initWithTarget:self selector:@selector(workOnSomeData:) object: ... Using &data d...

Coordinating typedefs and structs in std::multiset (C++)

I'm not a professional programmer, so please don't hesitate to state the obvious. My goal is to use a std::multiset container (typedef EventMultiSet) called currentEvents to organize a list of structs, of type Event, and to have members of class Host occasionally add new Event structs to currentEvents. The structs are supposed to be sor...

how to join a set of XElements to the values of a struct?

Let's say I have a struct that contains local environments: public struct Environments { public const string Dev = "DEV"; public const string Qa1 = "SQA"; public const string Prod1 = "PROD"; public const string Prod2 = "PROD_SA"; public const string Uat = "UAT"; } And I'd like to pull...

Initialize Static Array of Structs in C

I'm implementing a card game in C. There are lots of types of cards and each has a bunch of information, including some actions that will need to be individually scripted associated with it. Given a struct like this (and I'm not certain I have the syntax right for the function pointer) struct CARD { int value; int cost; // ...

struct bitfield max size (C99, C++)

Hello What is maximal bit width for bit struct field? struct i { long long i:127;} Can I define a bif field of size 128, 256 bit or larger? There are some extra-width vector types, like sse2, avx registers. ...

c++ Initializing a struct with an array as a member

Edited again because it originally wasn't clear that I'm trying to initialize the arrays at compile time, not at run time... I've got the following reduced testcase: typedef struct TestStruct { int length; int values[]; }; TestStruct t = {3, {0, 1, 2}}; TestStruct t2 = {4, {0, 1, 2, 3}}; int main() { return(0); } This...

How to sort an array of structs in ColdFusion

I have an array of structs in ColdFusion. I'd like to sort this array based on one of the attributes in the structs. How can I achieve this? I've found the StructSort function, but it takes a structure and I have an array. If this is not possible purely in ColdFusion, is it possible in Java somehow (maybe using Arrays.sort(Object[], Co...

Should I Make These Vectors Classes or Structs in C#

I am creating a geometry library in C# and I will need the following immutable types: Vector2f (2 floats - 8 bytes) Vector2d (2 doubles - 16 bytes) Vector3f (3 floats - 12 bytes) Vector3d (3 doubles - 24 bytes) Vector4f (4 floats - 16 bytes) Vector4d (4 doubles - 32 bytes) I am trying to determine whether to make them structs or clas...

Inserting non-pod struct into a GHashTable

Hi there, I'm trying to build a GHashTable of instances of a struct containing ints, a time_t and a few char*'s. My question is, how do you insert an instance of a struct into a GHashTable? there are plenty of examples of how to insert a string or an int (using g_str_hash and g_int_hash respectively), but I'm guessing thatI want to use...