struct

Some questions on C++ struct and array

Hi! I am relatively new to C++ and am having problems understanding struct. I have a struct declared as follow struct MyNode { int level; int index; MyNode children[4]; } However the code fails to compile and reports error C2148: total size of array must not exceed 0x7fffffff bytes. But the following code compiles stru...

Definitions of "primitive", "value type", "struct", "class", "wrap" in Java and C#

I have been trying to understand the use of "primitives" in Java and C# and the difference between them (if any). I have asked a series of questions on SO and some of the answers seem to confuse the issue rather than clarify it. Some answers (and some MS documentation) appear to provide contradictory statements. From SO http://stackove...

C struct initialization using labels. It works, but how? Documentation?

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 test = { second: 2, first: 1 }; printf("test.first=%d test.second=%d\n", test.first, test.second); } Surprisingly (to me), here's the...

How does Returning a Struct as an Interface work?

The following code works, but I can't figure out what's going on memory-wise. Where and how is the struct value t copied? interface ITest { void Hello(); } struct STest : ITest { public void Hello() { Console.WriteLine("Hello"); } } static ITest Make() { STest t = new STest(); return t; } static void Main(string[] arg...

Is it possible to change the default value of a primitive data type?

I recently created a generic Matrix<T> class that acts as a wrapper around a List<List<T>> collection. As far as I can tell, this class is working perfectly. I am running into a slight problem though regarding the default values of the T's. I create an instance of Matrix<int>(3, 3), which creates a 3x3 matrix of ints, all defaulted to 0...

How to delta encode a C/C++ struct for transmission via sockets

Hi, I need to send a C struct over the wire (using UDP sockets, and possibly XDR at some point) at a fairly high update rate, which potentially causes lots of redundant and unnecessary traffic at several khz. This is because, some of the data in the struct may not have changed at times, so I thought that delta-encoding the current C str...

Choosing C struct name for doxygen?

How can I tell Doxygen to use the first declaration in this code: typedef struct _decor_extents { int left; int right; int top; int bottom; } decor_extents_t; Cheers, Kris ...

* is illegal for a struct?

I tried to compile the following code, but the compiler wouldn't doing because " * is illegal for a struct" is that true? struct String { int length; int capacity; unsigned check; char ptr[0]; } String; void main(){ char *s; String *new_string = malloc(sizeof(String) + 10 + 1); } ...

OS API allocates members in struct. Free just the struct or every member first?

Let's say we have an array of PRINTER_INFO_2 like this: PRINTER_INFO_2* printers = (PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2) * 64); // room for 64 items Then we call EnumPrinters() to get a list of locally installed printers: EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)printers, ...); Here's the stru...

Changing value in memory through an SO in C

I'm writing a .SO that gets called by another program and I want to be able to flip a value in memory through a function in the .SO What I have so far is : int axptrace( int numArguments, char* pMessageBuffer, int* pMessageBufferSize, char* pData[], int* pDataLength[] ) { printf("Beginning dump attempt..\n"); unsigned int* wkp...

What (if any) are the implications of having an object or a nullable type as a field in a struct

For performance reasons I use structs in several use cases. If I have an object or a nullable type (another struct but nullable) as a member in the struct, is there an adverse effect on performance. Do I lose the very benefit I am trying to gain? Edit I am aware of the size limitations and proper use of structs. Please no more lectur...

Python File Slurp w/ endian conversion

It was recently asked how to do a file slurp in python: link text And it was recommended to use something like with open('x.txt') as x: f = x.read() How would I go about doing this to read the file in and convert the endian representation of the data? For example, I have a 1GB binary file that's just a bunch of single precision flo...

Marshalling structs from WM_COPYDATA messages

I am trying to get a C# WPF application to communicate with another application written in C using WM_COPYDATA. The C app is trying to send a struct as follows: typedef struct { int x; int y; char str[40]; double d; char c; } DATASTRUCT; In my C# app I have defined a struct as follows: [StructLayout(LayoutKind.Seq...

c# struct fields are "never assigned to" warnings

Based on http://alexreg.wordpress.com/2009/05/03/strongly-typed-csv-reader-in-c/, I created a DLL which can read different file types. I also have unit tests that run successfully. I create a struct and use it as the generic type. Anyway, when I compile, I get a warning on each of the struct fields. For example: field 'FileReader.Tes...

use MORE structs?

There have been several questions over the past few days about the proper use of null; here are three (one is mine): Best Practice: Should functions return null or an empty object? null objects vs. empty objects how do i explain that if (xyz == null) checks are not “protective”. While reading and thinking about this issue, the though...

c++: Initialize struct with one array containing all arguments

Hi, I am currently working on a small tokenizer template function which also casts the tokens to different objects. this works really nice aslong as all the strucs I cast to have the same number of items. what I would like to do know is to make the function cast to structs with any number of items. The bottleneck of the function for me ...

accessing struct variable inside getter setter in a c++ class

Okay, I have something like this in C++: class MyClass{ private: int someVariable; int someOtherVariable; struct structName{ int someStructVariable; int someOtherStructVariable; };//end of struct public: //getters & setters for the defined variables. int getSomeStructVariable() { // this does not work I get ...

Dealing with Structs in C

Suppose struct_name is the name of a struct I've defined, and array is a member in the struct defined as char array[o] what does the following line produce? (*struct_name).array an address location? ...

Problems returning vector stack reference

Hello, I am working on an application that builds a vector of structs for items in a given directory and returns a reference of the vector for it to be read, I receive the following errors when attempting to compile the example code below: 1. 'class std::vector<indexStruct, std::allocator<indexStruct> >' has no member named 'name' 2. n...

Invoke C dll functions,structs and callbacks in C#

Below is the header file.can anyone please give a idea to call the callback function below. //Function Prototype int PASCAL EXPORT RegisterCallbackFunctions (TCallbacks CallbackFuncs); //Data Structure struct TCallbacks { LPONUSSDREQUEST m_pOnRequest; LPONUSSDRESPONSE m_pOnResponse; }; struct TData { DWORD m_dwCmd; BYTE ...