struct

Why are .NET value types sealed?

It's not possible to inherit from a C# struct. It's not obvious to me why this is: Clearly you can't have a reference type that inherits from a value type; this wouldn't work It doesn't sound reasonable to inherit from one the primitive types (Int32, Double, Char, etc.) You'd need to be able to call (non-virtual) methods on the base us...

C++ bool array as bitfield?

Hi! let's say i need to store 8 bools in a struct, but i want to use for them only 1 byte together, then i could do something like this: struct myStruct { bool b1:1; bool b2:1; bool b3:1; bool b4:1; bool b5:1; bool b6:1; bool b7:1; bool b8:1; }; and with this i could do things like myStruct asdf; asd...

strcmp struct in c - different elements

I have a struct member that holds lots of string elements. What I want is to iterate the whole member of the struct and count only different elements (diff last names). struct log { char *last; }; ... struct log *l l->last = last_name; // loading *last member with data coming from last_name var ... What would be a good way to com...

(C#) Can struct be viewed in CLRProfiler?

As CLRProfiler use words like HEAP statistic, OBJECTS finalized, it made me think it will atmost only show boxed struct? So what if the structs are my source of problem? How can I know about it with CLRProfiler?? ...

Structs interface

When you define a new struct is better to define also an interface to that type (i.e. "setter" and "getter" functions) or to access members directly via . and -> operators? EDIT Plain C programming ...

Is there any way to loop through a struct with elements of diferent types in C?

Hi, my struct is some like this typedef struct { type1 thing; type2 thing2; ... typeN thingN; } my_struct how to enumerate struct childrens in a loop such as while, or for? thanks in advance. ...

Pbl xcode C++ typedef struct toto toto

Hi everyone, I am working on a C++ project on macOS X 10.6.2 with xcode. I tried to compile my code on windows and do not have any problem, I guess Linux is working but I don't have one with me right now. My problem is xcode do not accept this kind of instruction : struct direction { double x; double y; double z; double t; }; typede...

How do I send a struct from C# to VB6, and from VB6 to C#?

I need to send a struct from C# to a VB6 app, modify the data in VB6, and send the result back via windows messaging. How do I do this? I am able to send basic ints back and forth with PostMessage (using DllImport in C# and registering the vb6 app with windows messaging), but need to send more structured data, consisting of strings, in...

Why does GCC give me a syntax error when trying to return a struct pointer?

I'm using CodeLite on Ubuntu and for some bizzare reason GCC keeps throwing this error whenever I try to compile code with a function that returns a pointer to a struct: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token Here is an example I wrote up to demonstrate this error: #include <stdio.h> typedef struct ...

How to set a struct member of type string

I have a struct which contains a member called char *text. After I've created an object from the struct, then how do I set text to a string? ...

struct - sorting a c-string with qsort

I'm sorting a bunch of IPs, but for some reason they come in the wrong order. I'm not quite sure where could be the problem. 66.249.71.3 190.148.164.245 207.46.232.182 190.148.164.245 190.148.164.245 202.154.114.253 190.148.164.245 190.148.164.245 66.249.71.3 190.148.164.245 202.154.114.253 Here it is the wa...

Does system.Decimal use more memory than 'decimal'?

I heard someone say that in C#, capital Decimal is using more memory than lower case decimal, because Decimal is resolved to the lowercase decimal and that requires memory. Is that true? ...

Is this a proper usage of the struct element in C#? Kind of confused.

I'm making a class that will read information from resource files (doesn't matter the type of resource file, just for clarification) and pass the information on a Form for easy manipulation of information. My questions is should I use a struct to easily organize the information and then pass a List to a Form looking to utilize the infor...

unique elements - struct array

I have a sorted struct of IPs where I need to get the number of unique IPs, for some reason the way I'm doing it, is giving me a "0" as a result. Which in this case there should be 12 unique ips. The struct array containing the following elements: 195.55.121.242 212.80.168.34 65.55.106.114 65.55.207.30 65.55.207.95 65.55.230.237 ...

Why does C have a distinction between -> and . ?

OK, this is of no serious consequence, but it's been bugging me for a while: Is there a reason for the distinction between the -> and . operators? Of course, the current rule is that . acts on a struct, and -> acts on a pointer-to-struct (or union). But here's how it works in practice. Let s be a struct incuding an element x, and let p...

C structure with pointer to self

Hi! Is it posible to define a structure with a pointer to that type of structure? What I mean is: typedef struct { char* name; node* parent; } node; As far as I tried or read, I don't know how to do this or if it's even possible. ...

C# Generics, Constrain to Specific Structs

Is it possible to constrain a genericised method to accept only specific types of struct? This is OK I believe: string Add<T>(object value, T expiration) where T : struct; but this isn't it appears: string Add<T>(object value, T expiration) where T : Struct1, Struct2; Note: the structs I wish to constrain it to are DateTime or Tim...

Nested structures

The following code compiles on a C++ compiler. #include<cstdio> int main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; Would there be any difference in behavior while compiling with a C compiler? i.e. would there be any compiler error? ...

How to set an autoproperty in the constructor of a struct?

Why is this valid public struct MyStruct { public MyStruct(double value) { myField = value; } private double myField; public double MyProperty { get { return myField; } set { myField = value; } } } and this is not public stru...

C# equivalent of python's struct.pack

Is there a library for C# that allows similar functionality to python's struct from the standard library? One can emulate the struct library quite closely with real aligned structs. But I didn't find yet any way to directly control the endianess in C#'s structs (the C#'s structs seems to be geared more towards COM interop, and less towa...