struct

Segmentation fault when returning a struct

I am trying to do a pretty simple thing - it is reading a file and then turning it into a char** splitting it into lines. However when I return a struct containing the char** and size i get Segmentation fault. I read here: http://stackoverflow.com/questions/3047163/c-segmentation-fault-before-during-return-statement that it's probably "m...

Is it always evil to have a struct with methods?

I've just been browsing and spotted the following... http://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c The consensus there is that, by convention, you should only use struct for POD, no methods, etc. I've always felt that some types were naturally structs rather than classes, yet could still have a ...

typedef stuct problem in C

Hello there I am facing a weird problem I have defined I a structure in a C header file: typedef struct iRecActive{ char iRecSID[32]; unsigned char RecStatus; int curSel; }iRecAcitve_t; but when I use the same structure in another file, the compiler doesn't recognize the structure even though I have double checked that...

typedef stuct problem in C (illegal use of this type as an expression)

Possible Duplicate: typedef stuct problem in C Hello there I am facing I have defined I a structure in a C header file: typedef struct iRecActive{ char iRecSID[32]; unsigned char RecStatus; int curSel; }iRecAcitve_t; but when I use the same structure in another file, the compiler gives some error: error C227...

c - grouping strings in a struct

I have a bunch of strings that look like: 'Hello1-FOO', 'Aello2-FOO', 'Bye1-BAR', 'Bye3-BAR', 'Hello22-FOO', 'Bye4-BAR', 'Welcome-BAR' ... All of them are stored on a struct. struct str { char *strings; } ... struct str **t_str; size_t j; t_str = malloc(sizeof *t_str * 20); for (j = 0; j < 20; j++) t_str[j] = malloc(sizeof *t...

generic list of value types with sequential layout and pack size -> BUG?!

The following code throws an ExecutionEngineException when I run the release build executable (start exe file). Is this a bug or is it normal behavior? value type with pack size = 1: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct RunLong { public byte Count; public long Value; public RunLong(byte count, long...

How to use a C++ string in a structure when malloc()-ing the same structure?

I wrote the following example program but it crashes with segfault. The problem seems to be with using malloc and std::strings in the structure. #include <iostream> #include <string> #include <cstdlib> struct example { std::string data; }; int main() { example *ex = (example *)malloc(sizeof(*ex)); ex->data = "hello world"; std::c...

How to read from a file except the last line in C?

I am having a file where i need to read the data and store it into a structure. 10001 john 10002 david 10003 randy 10/10/2010 15:50:55 Updated by : Name now for the above file i need to read the data from '10001' & 'john' till '10003' & 'randy' except the last line(End of the file). How to do it in C? Update : last line will be dy...

Better way to declare this huge struct?

I am creating an application which uses a vCard struct. Currently, this struct looks like this: typedef struct { char *version; char **names; char *formatted_name; char *nickname; char *organisation; char *title; struct { /* Emails */ char *global_ty...

C++ Performance of structs used as a safe packaging of arrays

In C or C++, there is no checking of arrays for out of bounds. One way to work around this is to package it with a struct: struct array_of_foo{ int length; foo *arr; //array with variable length. }; Then, it can be initialized: array_of_foo *ar(int length){ array_of_foo *out = (array_of_foo*) malloc(sizeof(array_of_foo)); out...

statically filling a huge structure

I have a huge data in excel sheet. I need to prepare a structure for that data and fill the data. I can do it in 2 ways. statically fill the structure during struct initialization struct x a[] = { } Dynamically fill the structure by allocating memory and filling it in a function. My structure also looks little complicated. How do I f...

How to Assign the value to Main /Parent Structure in a Nested Structure?

Hi I have writen an Nested Structure in C# . Find the code snippet below: public struct SMB_MESSAGE { #region SMB Parameter public struct SMB_PARAMETERS { public byte WordCount; public ushort[] Words; } #endregion #region SM...

P/Invoke Interop Assistant Llike Tool for Python ctypes or struct Modules

The P/Invoke Interop Assistant tool has been very helpful when I've had to marshal from c style structs into managed C# types. Are there any similar tools for the Python ctypes or struct modules? ...

class and struct in c++

Possible Duplicate: What are the differences between struct and class in C++ what is the practical difference between class and struct in c++ except the default definition of members to be public (in struct) and private (in class)? if this is the only difference why do we need both? ...

C++ memory management for a vector with variable length items

Take a variable length struct (if this were a real program, an int array would be better): #include <vector> struct list_of_numbers(){ int length; int *numbers; //length elements. }; typedef std::vector<list_of_numbers> list_nums; //just a writing shortcut (...) And build a vector out of it: list_nums lst(10); //make 10 lists. l...

How to get the Updated Size of Structure?Size of the Structure not getting Updated When I add values to dynamic array Fields

Hi, This is related to my previous question, and thought will make this as a sparate question as it will make more sense. I have created my Struct as : public struct Smb_Parameters { public byte WordCount; public ushort[] Words; } Without Assigning any Values when I try to get the size of the S...

C++ typedef and struct question

typedef struct { int y; int weight; struct edgenode * next; }edgenode; This code is giving error : 'edgenode' : redefinition; different basic types It works fine in C code. Why? ...

ctypes.Structure Modify _fields_ at Run Time

Is it possible to modify the fields definition of the ctypes.Structure after it's been imported? Something like: from ctypes import * class A_STRUCT(Structure): _fields_ = [("one",c_int)] A_STRUCT._fields_.append(("two",c_int)) x = A_STRUCT() print x.one print x.two Not surprisingly this fails with: 0 Traceback (most recent ...

Can __attribute__((packed)) affect the performance of a program?

I have a structure called log that has 13 chars in it. after doing a sizeof(log) I see that the size is not 13 but 16. I can use the __attribute__((packed)) to get it to the actual size of 13 but I wonder if this will affect the performance of the program. It is a structure that is used quite frequently. I would like to be able to rea...

How are structs laid out in memory in C++?

Is the way C++ structs are laid out set by the standard, or at least common across compilers? I have a struct where one of its members needs to be aligned on 16 byte boundaries, and this would be easier if I can guarantee the ordering of the fields. Also, for non-virtual classes, is the address of the first element also likely to be th...