See this GTK callback function:
static gboolean callback(GtkWidget *widget, GdkEventButton *event, gpointer *data)
{
AnyClass *obj = (AnyClass*) data;
// using obj works
}
(please note the gpointer* on the data). And then the signal is connected using:
AnyClass *obj2 = new AnyClass();
gtk_signal_connect(/*GTK params (...)*/, ...
What's the meaning of ~0 in this code?
Can somebody analyze this code for me?
unsigned int Order(unsigned int maxPeriod = ~0) const
{
Point r = *this;
unsigned int n = 0;
while( r.x_ != 0 && r.y_ != 0 )
{
++n;
r += *this;
if ( n > maxPeriod ) break;
}
return n;
}
...
I am currently writing my own shell program. This simple shell can just execute commands.
When executing commands like vi or calc which require input from the terminal , the command is getting executed and is waiting for the input from the user. But I am unable to give any input on the screen.
How should the input be handled during the...
The following program is essentially the same as the one described here. When I run and compile the program using two threads (NTHREADS == 2), I get the following run times:
real 0m14.120s
user 0m25.570s
sys 0m0.050s
When it is run with just one thread (NTHREADS == 1), I get run times significantly better even th...
This an extract from a c program that should demonstrate a bufferoverflow.
void foo()
{
char arr[8];
printf(" enter bla bla bla");
gets(arr);
printf(" you entered %s\n", arr);
}
The question was "How many input chars can a user maximal enter without a creating a buffer overflow"
My initial answer was 8, because the char-arr...
Sorry for the trivial question, but I can't find this infomation from the manual. I am developping a module for python using C api; how can I create a variabile that is seen as global from python? For example if my module is module I want to create a variable g that do this job:
import module
print module.g
in particular g is an integ...
Hi,
I am new to c programming. Could anyone please tell me what's wrong with
the following program?
typedef struct Person_s
{
int age;
char name[40];
} Person_t;
int process_list(int *countReturned, Person_t **p_list)
{
Person_t *rowPtr=0;
//the actual program will fethc data from DB
int count =1;
if(!((*p_list) = ...
Is there a fast way to cast double values to shorts (16 bits signed), currently I'm doing something like this:
double dval = <sum junk>
int16_t sval;
if (val > int16_max) {
sval = int16_max;
} else if (val < int16_min) {
sval = int16_min;
} else
sval = (int16_t)val;
I suspect there's a fast way to do this using SSE that wi...
Given the following code (it's a macro that generates code for a list data structure, based on the contained type).
list.h
#ifndef _LIST_H
#define _LIST_H
#ifdef __cplusplus
extern "C" {
#endif
#define LIST_TEMPLATE_INIT(type) \
typedef struct __list_s_##type { \
struct __list_s_##type *next; \
type value; \
...
This seems like it should be really simple, but for some reason, I'm not getting it to work. I have a string called seq, which looks like this:
ala
ile
val
I want to take the first 3 characters and copy them into a different string. I use the command:
memcpy(fileName, seq, 3 * sizeof(char));
That should make fileName = "ala", right...
I have very little idea what I'm doing here, I've never done anything like this before, but a friend and I are writing competing chess programs and they need to be able to communicate to each other.
He'll be writing mainly in C, the bulk of mine will be in Python, and I can see a few options:
Alternately write to a temp file, or succe...
I have some verticies and then I apply a glrotate(). I'd want to now what my verticies became after this transformation. How could I do this?
Thanks
...
I'm sure there's not just 1 answer to this but, do game engines actually change the vectors in memory, or use gltransformations? Because pushing and popping the matrix all the time seems inefficient, but if you keep modifying the verticies you cant make use of display lists. So I'm wondering how it's done in general. Thanks
...
Hi,
When coding in either C or C++, where should I have the #include's?
callback.h:
#ifndef _CALLBACK_H_
#define _CALLBACK_H_
#include <sndfile.h>
#include "main.h"
void on_button_apply_clicked(GtkButton* button, struct user_data_s* data);
void on_button_cancel_clicked(GtkButton* button, struct user_data_s* data);
#endif
callback...
Right now I am using fread() to read a file, but in other language fread() is inefficient i'v been told. Is this the same in C? If so, how would faster file reading be done?
...
I'm using the GLUTesselator for Polygons. Right now the vertex callback does glvertex2f and gltex2f. Would it be better simply to collect the verticies from the vertex callback in a std::vector then use gldrawarrays()? Or would this actually be less efficient since it has to put the verts and texture coordinates in a vector?
Thanks
...
What's the simplest, but efficient compression algorithm?
Deflate, lzma, etc. aren't valid options. I need something that compiles really small, like: RLE, LZX, Huffman, etc..
Note: The data is 95% ASCII text
Edit: Data is ~20kb at the moment, but i expect it to grow up to 1mb
...
I'm creating a drawing application with OpenGL. I'v created an algorithm that generates gradient textures. I then map these to my polygons and this works quite well. What I realized is how much memory this requires. Creating 1000 gradients takes about 800MB and that's way too much. Is there an alternative to textures, or a way to compres...
I have a c pointer to a structre type called uchar4 which looks like
{
uchar x;
uchar y;
uchar z;
uchar w;
}
I also have data passed in as uint8*. I'd like to create a uchar* pointing to the data at the uint8* so I've tried doing this:
uint8 *data_in;
uchar4 *temp = (uchar4*)data_in;
However, the first 8 bytes a...
I'd like to know if my program is accessing NULL pointers or stale memory.
The backtrace looks like this:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x2b0fa4c8 (LWP 1333)]
0x299a6ad4 in pthread_mutex_lock () from /lib/libpthread.so.0
(gdb) bt
#0 0x299a6ad4 in pthread_mutex_lock () from /lib/libpthread.s...