struct

How to use struct in c?

This is a code for linked list in c programming language. #include <stdio.h> /* for printf */ #include <stdlib.h> /* for malloc */ typedef struct node { int data; struct node *next; /* pointer to next element in list */ } LLIST; LLIST *list_add(LLIST **p, int i); void list_remove(LLIST **p); LLIST **list_search(LLIST **n,...

Pad a C++ structure to a power of two

I'm working on some C++ code for an embedded system. The I/O interface the code uses requires that the size of each message (in bytes) is a power of two. Right now, the code does something like this (in several places): #pragma pack(1) struct Message { struct internal_ { unsigned long member1; unsigned long member2; ...

default visibility of C++ class/struct members

In C++, why is private the default visibility for members of classes, but public for structs? ...

C++ byte stream

Hi Everyone, For a networked application, the way we have been transmitting dynamic data is through memcpying a struct into a (void*). This poses some problems, like when this is done to an std::string. Strings can be dynamic length, so how will the other side know when the string ends? An idea I had was to use something similiar to Java...

Python Class Factory to Produce simple Struct-like classes.

While investigating Ruby I came across this to create a simple Struct-like class: Person = Struct.new(:forname, :surname) person1 = Person.new('John', 'Doe') puts person1 #<struct Person forname="John", surname="Doe"> Which raised a few Python questions for me. I have written a [VERY] basic clone of this mechanism in Python: def Str...

Serialize/marshal/reverse engineer unknown structure

Is there a way to deserialize or marshal or somehow parse a byte array back into a structure when you don't know what that structure was in the first place? The structure probably came from C++. Some background: I have a flight simulator for R/C planes and I'm trying to figure out if I can automate it. There is no API. I know how to aut...

When should Structs be used in C#?

Possible Duplicates: When to use struct in C#? When should I use a struct instead of a class? What would be some instances when one would want to use Structs in C#? Is it when you want a lightweight, immutable class? How will the stack vs heap allocation effect me and what should I be aware of? Are there any other instances ...

How can I check if a struct has been initialized?

I'm using an NSRange (a struct) and initializing it like this: @interface MyViewController : UIViewController { NSRange currentRange; } NSRange has a location and length field. How can I check to see if the struct has been initialized with a value? I tried: if (myRange.length == nil) but the compiler complained about comparing...

how to refer to the current struct in an overloaded operator?

Hi! I have a struct for which i want to define a relative order by defining < , > , <= and >= operators. actually in my order there won't be any equality, so if one struct is not smaller than another, it's automatically larger. I defined the first operator like this: struct MyStruct{ ... ... bool operator < (const MyStruct &b) const ...

Char array in a struct - incompatible assignment?

Hi! I tried to find out what a struct really 'is' and hit a problem, so I have really 2 questions: 1) What is saved in 'sara'? Is it a pointer to the first element of the struct? 2) The more interesting question: Why doesn't it compile? GCC says "test.c:10: error: incompatible types in assignment" and I can't figure out why... (This ...

Mix of template and struct

I have a template class defined as follow : template <class T1, class T2> class MyClass { }; In this class, I need a struct that contains one member of type T1. How can I do that ? I tried the following, but it didn't work : template <class T1, class T2> class MyClass { typedef struct { T1 templateMember; // rest...

setting the maximum segment size in the tcp header

I am putting together a port scanner as a learning exercise. My problem is I'm trying to set the maximum segment size option(MSS) in the TCP header. I had a look at tcp.h, but I'm having trouble figuring out how to set it. I was hoping there would be an option like this: tcp_header->mss(32000); Something similar to the above was in tc...

Does ColdFusion have a short syntax for creating a struct?

Is there any "short" syntax for creating a struct in ColdFusion? I'd like to replace this verbose code: <cfscript> ref = StructNew(); ref.Template = "Label"; ref.Language = "en"; stcML = GetPrompts(ref); </cfscript> with something more like a JavaScript object: <cfscript> stcML = GetPrompts({ Template: "Label", Language: "...

Objective C Structs and Memory Management

Simple question - do i need to free or release structs. My reason for asking is that I'm use a NSInvocation and the SEL type is a struct. Just want to know if I need to release it. Thanks. ...

access time for small array vs small struct in c#

Hello, I need to process about 500,000 data points each consisting of 4 decimals. I'd like to use and array of structs to do this. Would this be much slower than using an array of arrays? It seems that memory won't be an issue, but speed will - it needs to be fast. Quick code sample of two options: Option 1: public struct Struct...

Is it possible to list variable names of a struct in objective-c?

if I have a struct say: struct myStruct { int someInt; flot someFloat; } Is there any way to get a list of the member variables? ie. someInt, someFloat? ...

Converting this C signature to C# for P/Invoke

I have the following C function: int w_ei_connect_init(ei_cnode* ec, const char* this_node_name, const char *cookie, short creation); ei_cnode looks like this: typedef struct ei_cnode_s { char thishostname[EI_MAXHOSTNAMELEN+1]; char thisnodename[MAXNODELEN+1]; char thisalivename[EI_MAXALIVELEN+1]; ...

Using in_addr in C#

I'm trying to interact with a native DLL using P/Invoke, but it requires an in_addr struct parameter. I keep seeing many different kinds of definitions for it, but which is the best to use? Also, how can I convert a C# IPAddress object to an in_addr struct? ...

Why is this struct cleared after being created?

I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr { public Anonymous1 S_un; [StructLayoutAttribute(LayoutKind.Explicit)] public struct Anonymous1 { [FieldOffsetAttribute(0)] public Anonymous2 S_un_b; [FieldOffsetAttribute(0)] public Anonymous3 S_un_w; [FieldOffset...

How do I initialise a global array of structs in D?

In aid of my one-man quest to populate SO with D questions (=p), I've run into another problem; initialising an array of structs globally. Observe: struct A { int a; float b; } A[2] as; as[0] = {0, 0.0f}; as[1] = {5, 5.2f}; void main() {} Results in: $ dmd wtf.d wtf.d(8): no identifier for declarator as[0] wtf.d(9): no ide...