c

_Bool and bool: How do I solve the problem of a C library that uses _Bool?

I've written a collection of data structures and functions in C, some of which use the _Bool data type. When I began, the project was going to be pure C. Now I am investigating using a C++ based GUI tool kit and have made the backend code into a library. However, when compiling the C++ GUI the following error is emitted by the compiler:...

How to print unsigned int value as a time string in C

I need to print this value as a time string to Mon 16-Aug-2010 06:24 format or something similar. unsigned int t = 1281920090; ...

What is the K&R equivalent for C++?

Possible Duplicate: The Definitive C++ Book Guide and List I'm in the process of learning C, and am reading the K&R book thoroughly and trying to do as many of the exercises as possible. I'm looking at picking up C++ after I'm comfortable with C. Is there a de facto C++ book? Particularly one with good exercises? Thanks ...

How can I assign values to a function pointers members in a structure

struct a { int (*ptr1)(); int (*ptr2)(); int data; }; typedef struct { struct a x; }all; int fun1() { return 5; }; int fun2() { return 9; }; I can assign like all *mem = (all*)malloc(sizeof(all)); mem->x.ptr1 = fun1; mem->x.ptr2 = fun2; Is there any other way to assign these function pointers? Is it possible to assi...

C puzzle: how will you print something on console?

/*you cannot change anything from here below*/ main() { exit(0); } /*you cannot change anything from here up*/ This was asked during an interview. I was told to print something on console. anybody? ...

C compiler's language

Hi, I just want to know the language in which the C compiler was written. Please say something other than C. ...

Python Dbus : SystemBus and SesssionBus mainloops

Hello, I need to run SystemBus and SessionBus mainloops in my python application. So I would like to ask what is the best way to do this ? To run SystemBus mainloop in application's main thread and SessionBus mainloop in another ? Regards, Levon ...

Names of files accessed by an application.

Hello Everyone! Any help with this problem would be fantastic. I appreciate all contributions! Let us say I'm running a daemon that is observing the behaviour of the app that has keyboard focus. I have it's PID and process name. Is there any way I can see what files that application is accessing? I'm programming in Objective-C, Cocoa ...

Syslog custom priorities

Is there a way one can use custom priorities in syslog daemon or rsyslog daemon? i.e. i am unable to locate a configuration change which achives it.. the other thing i can do is perhaps play with it's source. Cheers! ...

Parsing a XML file in C using MiniXML

I'm using the MiniXML library to parse a XML file in C, however when i try to read the node's value it returns NULL. Here's the code: FILE *fp; mxml_node_t *tree; fp = fopen("test.xml", "r"); tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK); fclose(fp); mxml_node_t *node; for(node = mxmlFindElement(tree, tree,"node",NULL, NULL,MXML_...

socklen_t undeclared when compiling .c code

I am trying to compile this .c code in windows using MinGW (gcc file.c -o compiled.exe): /***************************************************/ /* AUTHOR : LAW CHIU YUEN */ /* FILENAME : smtpr.c */ /***************************************************/ #ifdef WIN32 #include <windows...

What is the reason C compiler demands that number of columns in a 2d array will be defined?

Hello, given the following function signature: void readFileData(FILE* fp, double inputMatrix[][], int parameters[]) this doesn't compile. and the corrected one: void readFileData(FILE* fp, double inputMatrix[][NUM], int parameters[]) my question is, why does the compiler demands that number of columns will be defined when handli...

How to format unsigned int into 8 digit hexadecimal number?

I want to format an unsigned int to an 8 digit long string with leading zeroes. This is what I have so far: unsigned int number = 260291273; char output[9]; sprintf(output, "%x", number); printf("%s\n", output); // or write it into a file with fputs Prints "f83bac9", but I want "0f83bac9". How can I achieve the formatting? ...

C code for XOR linked list

I have been trying to Implement XOR linked list and its operations but I have not been able to do it properly. Is it possible to implement it in C since XOR link list involves operations on addresses?? I would be very thankful if some actual working code is given. ...

Thread-ring benchmark

Today I was doing the thread ring exercise from the Programming Erlang book and googled for other solutions to compare. I found that the language shootout has exactly this the same problem as a benchmark. I had the impression that this is an area where Erlang should be fastest, but turns out that C and C++ are again on top. My suspicion ...

Will a C conditional always return 1 or 0?

Do C conditional statements always return [1 or 0], or do they return [0 or 'something other than zero']. I ask because: pseudo code - foo(address, shouldSend): register >>= 1 register <<= 1 // to clear bit in first position register |= shouldSend // to signal whether it should send or not the problem occurs if somebody ...

how about .bss section not zero initialized

as we know .bss contains un-initialized variables. if in c code, programer initialize the variables before using them. then .bss is not necessary to be zero before executing C code. Am I right? Thanks ...

PyArg_ParseTuple and a callback function pointer

I have code like the following: PyObject *callback; PyObject *paths; // Process and convert arguments if (!PyArg_ParseTuple(args, "OO:schedule", &paths, &callback)) return NULL; What exactly happens inside PyArg_ParseTuple? My guess is that callback gets the function pointer I passed to args (also PyObject...

Using and returning output in C macro

I'm trying to instrument some code to catch and print error messages. Currently I'm using a macro somethng like this: #define my_function(x) \ switch(function(x)) { \ case ERROR: \ fprintf(stderr, "Error!\n"); \ break; \ } Normally, I never capture the function output and this works fine. But I've found a couple ca...

the select() socket system call on mac osx taking a long time for reads

We're developing a cross-platform network application that needs to send and receive data over TCP. On linux we are using select() to wait on both send and receive to make sure that the socket is ready. However, on OSX the select for read takes an absurd amount of time to return -- over 20 seconds. select() isn't timing out -- our timeou...