I'm having trouble debugging a segmentation fault. I'd appreciate tips on how to go about narrowing in on the problem.
The error appears when an iterator tries to access an element of a struct Infection, defined as:
struct Infection {
public:
explicit Infection( double it, double rt ) : infT( it ), recT( rt ) {}
double infT; // in...
How do I go about opening a binary data file in Python and reading back the values one long
at a time, into a struct. I have something like this at the moment but I think this will keep overwriting idList, I want to append to it, so I end up with a tuple of all the long values in the file -
file = open(filename, "rb")
try:
...
I have an array of structs called leaders. The struct class looks like this, for contextual info:
class Leader < Struct.new(:rank, :user); end
Two questions:
How do I sort the array of structs by rank?
How do I sort the array of structs by rank and by user.created_at?
...
The following function writes a struct to a file.
#define PAGESIZE sizeof(BTPAGE)
#define HEADERSIZE 2L
int btwrite(short rrn, BTPAGE *page_ptr)
{
long addr;
addr = (long) rrn * (long) PAGESIZE + HEADERSIZE;
lseek(btfd, addr, 0);
return (write(btfd, page_ptr, PAGESIZE));
}
The following is...
Can a struct contain other structs?
I would like to make a struct that holds an array of four other structs. Is this possible? What would the code look like?
...
typedef struct queue {
int q[max];
int qhead;
int qrear;
} queue;
void init_queue(queue *QUEUE)
{
QUEUE.qhead = 0;
QUEUE.qrear = -1;
}
void enqueue(queue *QUEUE,int data)
{
QUEUE.qrear++;
QUEUE.q[QUEUE.qrear] = data;
}
int process_queue(queue *QUEUE)
{
if(QUEUE.qhead > QUEUE.qrear)
return -1;
else
return Q...
As part of answering another question, I came across a piece of code like this, which gcc compiles without complaint.
typedef struct {
struct xyz *z;
} xyz;
int main (void) {
return 0;
}
This is the means I've always used to construct types that point to themselves (e.g., linked lists) but I've always thought you had to name t...
Hi, I need to provide a C static library to the client and need to be able to make a struct definition unavailable. On top of that I need to be able to execute code before the main at library initialization using a global variable.
Here's my code:
private.h
#ifndef PRIVATE_H
#define PRIVATE_H
typedef struct TEST test;
#endif
pri...
I am trying to activate #pragma pack(push, 8) on ubuntu 10.4 (8.10 would also be nice), which uses gcc 4.4.3, but I can't get it to work. Is there something more that need to be done?
There is not even a warning if I compile with -Wunknown-pragmas so gcc seems at least to acknowledge it as a known pragma.
It would be nice to use the pa...
Hello everbody,
as said above, I wrote a little Python script that reads WOFF files (my own free fonts), extracts the embedded TrueType font data tables and rewrites them into TrueType font files. Well, it should theoretically. :-)
I read the specs (WOFF -- TrueType) and did everything as stated there. Here I posted a short overview of...
ive got a struct problem it returns:
cd.h:15: error: two or more data types in declaration specifiers
its probably something simple ...
struct cd {
char titel[32];
char artiest[32];
int speelduur;
};
typedef struct cd CD;
struct cdlijst{
CD *item;
struct cdlijst *next;
}
...
Hi,
In the ARM ABI documentation I come across functions defined like:
__value_in_regs struct bar foo(int a, int b) {
...
}
but GCC(4.3.3) doesn't allow it and all I could find are references to some RealView compiler.
Is there any way of doing this from GCC?
I have tried -freg-struct-return but it doesn't make a difference. As ...
Ive got a task in C to sort a struct by using qsort
struct user {
enum SEX{m, f} sex;
char name[32];
char phonenr[32];
};
typedef struct user User;
the users will be stored in a array of 25 elements
but how do i sort them on something like name ?
...
Why do this:
// If parameter cannot be cast to Point return false.
TwoDPoint p = obj as TwoDPoint;
if ((System.Object)p == null)
{
return false;
}
Instead of this:
// If parameter cannot be cast to Point return false.
TwoDPoint p = obj as TwoDPoint;
if (p == null)
{
return false;
...
I always wanted to know what is the real thing difference of how the compiler see a pointer to a struct (in C suppose) and a struct itself.
struct person p;
struct person *pp;
pp->age, I always imagine that the compiler does: "value of pp + offset of atribute "age" in the struct".
But what it does with person.p? It would be almost th...
I am coding a breakout clone. I had one version in which I only had one level deep of structures. This version runs at 70 fps.
For more clarity in the code I decided the code should have more abstractions and created more structs. Most of the times I have two two three level deep of structures. This version runs at 30 fps.
Since there ...
In this article : http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc03defst.htm
What's means the sentence "In C, a structure member may be of any type except "function returning T" (for some type T)"
Thanks for all the answers!
...
Hello!
Trying to understand why this doesn't work. I keep getting the following errors:
left of '->nextNode' must point to class/struct/union/generic type
(Also all the lines with a -> in the function new_math_struct)
Header file
#ifndef MSTRUCT_H
#define MSTRUCT_H
#define PLUS 0
#define MINUS 1
#define DIVIDE 2
#defi...
Ok i have a struct in my C++ program that is like this:
struct thestruct
{
unsigned char var1;
unsigned char var2;
unsigned char var3[2];
unsigned char var4;
unsigned char var5[8];
int var6;
unsigned char var7[4];
};
When i use this struct, 3 random bytes get added before the "var6", if i delete "var5" it's still before "var6" ...
I am new to C++, and let's say I have two classes: Creature and Human:
/* creature.h */
class Creature {
private:
public:
struct emotion {
/* All emotions are percentages */
char joy;
char trust;
char fear;
char surprise;
char sadness;
char disgust;
char anger;
...