I am writing an application in C# which is going to do extensive calculations. Everything is going around basic struct - Value. It is basically double with some additional parameters (accuracy etc.)
It has to be a struct, because there will be too many of them created to afford heap allocation.
Now, I need to make sure they all are corre...
If you have a binary file format (or packet format) which is described as a C structure, are there any programs which will parse the structure and turn it into neat documentation on your protocol?
The struct would of course contain arrays, other structures, etc., as necessary to describe the format. The documentation would probably nee...
I have the following construction:
typedef struct bucket {
char *key;
ENTRY *data;
struct bucket *next;
} bucket;
typedef struct {
size_t size;
bucket **table;
} hash_table;
But I have no idea how to allocate memory for that. I tried:
hash_table* ht = malloc(sizeof(hash_table)*101);
in order to create a hashta...
I'm fiddling with calling DLLs from C#, and came across the need to define my own structs. Lots of articles force a sequential layout for the struct with
[StructLayout(LayoutKind.Sequential)]
struct Foo ...
So, I followed suite, and my programme worked. Now, when I took the line out, it still works. Why do I need it?
...
I have a type which I consider use it as struct.
It represents single value
It is immutable
But the problem is, it has 6 fields of int.
So which solution I should use for this type?
keep using struct?
change to class?
or pack 6 integers into an array of int, so it has only one field
EDIT
Size of struct with 6 integer fields is ...
Kicking around some small structures while answering this post, I came across the following unexpectedly:
The following structure, using an int field is perfectly legal:
struct MyStruct
{
public MyStruct ( int size )
{
this.Size = size; // <-- Legal assignment.
}
public int Size;
}
However, the following...
If I have a class as follows
class Example_Class
{
private:
int x;
int y;
public:
Example_Class()
{
x = 8;
y = 9;
}
~Example_Class()
{ }
};
And a struct as follows
struct
{
int x;
int y;
} example_struct;
Is the...
Given a struct, e.g.
typedef struct
{
int value;
} TestStruct;
Why does the following code (in the context of an Objective-C class running on the IPhone) throw a "non-aligned pointer being freed" exception?
TestStruct ts = {33};
free(&ts);
N.B. My uber goal is to use a C library with many vector-math functions, hence the need to ...
Consider the following:
typedef struct
{
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
} Matrix;
@interface TestClass : NSObject
{
Matrix matrix;
}
- (TestClass *) init;
@end
@implementation TestClass
- (TestClass *) init
{
self = [super init];
matrix = (Matri...
In C, is there a difference between writing "struct foo" instead of just "foo" if foo is a struct?
For example:
struct sockaddr_in sin;
struct sockaddr *sa;
// Are these two lines equivalent?
sa = (struct sockaddr*)&sin;
sa = (sockaddr*)&sin;
Thanks /Erik
...
Is there any advantage over using a class over a struct in cases such as these?
(note: it will only hold variables, there will never be functions)
class Foo {
private:
struct Pos { int x, y, z };
public:
Pos Position;
};
Versus:
struct Foo {
struct Pos { int x, y, z } Pos;
};
Similar questions:
http://stackov...
I'm trying to convert a struct to a char array to send over the network. However, I get some weird output from the char array when I do.
#include <stdio.h>
struct x
{
int x;
} __attribute__((packed));
int main()
{
struct x a;
a.x=127;
char *b = (char *)&a;
int i;
for (i=0; i<4; i++)
printf("%02x ", b[i]);
...
I have a struct like this:
class Items
{
private:
struct item
{
unsigned int a, b, c;
};
item* items[MAX_ITEMS];
}
Say I wanted to 'delete' an item, like so:
items[5] = NULL;
And I created a new item on that same spot later:
items[5] = new item;
Would I still need to call delete[] to clean this up? Or won't this be needed...
Following the discussions here on SO I already read several times the remark that mutable structs are evil (like in the answer to this question).
What's the actual problem with mutability and structs?
...
Hello,
This code doesn't appear to be correct in ANSI-C, but ok in C99 :
struct a { int x; int y; } z;
What are the differences about struct in C99 and ANSI-C ?
Edit: I forgot the "a", my bad. This code compiles ok with gcc in C99 mode, but is a parse error on splint, which is known to not support all the C99 extensions.
Edit2: here...
Hi,
I am attempting to copy the members of a struct containing a mixture of ints, char's and arrays of chars into a byte array to send to a serial line. So far I have
// struct msg_on_send
// {
// char descriptor_msg[5];
// int address;
// char space;
// char cmdmsg[5];
// char CR;
// char LF;
// };
/...
I'm pretty sure this is possible, because I'm pretty sure I've seen it done. I think it is awesome, but I will gladly accept answers along the lines of "this is a terrible idea because ____".
Say we have a basic struct.
struct vertex
{
float x, y, z;
};
Now, I want to implement aliases on these variables.
vertex pos;
vertex col;...
Previously, when I needed to store a number of related variables, I'd create a class.
function Item(id, speaker, country) {
this.id = id;
this.speaker = spkr;
this.country = country;
}
var myItems = [
new Item(1, 'john', 'au'),
new Item(2, 'mary', 'us')
];
But I'm wondering if this is a good practice. Are there any...
Hello
I am (successfully) calling the Windows FilterSendMessage function in c# using the following pinvoke signature:
[DllImport("fltlib.dll")]
public static extern IntPtr FilterSendMessage(
IntPtr hPort,
IntPtr inBuffer,
UInt32 inBufferSize,
IntPtr outBuffer,
UInt32 outBufferSize,
ou...
How can i have a pointer to the next struct in the definition of this struct? :
typedef struct A {
int a;
int b;
A* next;
} A;
this is how i first wrote it but it does not work.
...