c

Portable way to link statically against one of the libraries

I am creating a utility which depends on libassuan aside other depends. While these ‘others’ provide shared libraries, libassuan comes with static one only. libassuan comes with simple libassuan-config tool which is meant to provide CFLAGS & LDFLAGS for the compiler/linker to use. These LDFLAGS refer to the library as -lassuan. The res...

How would I allocate memory to a char pointer if I don't know the size?

I have some sort of recursive function, but I need to parse a string, I don't know how long the string could it be. What si the appropiate way to allocate memory for that? ...

Wrapping Mutually Dependent Structs in Pyrex

Hello, I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so: typedef struct a { b * b_pointer; } a; typedef struct b ...

Simple Generation of GUID in C

I feel like GUID/UUID questions have been done to death here, but I can't seem to find quite what I'm looking for. I need a function that will generate V4 GUIDs in C, i.e. something that is essentially compatibile with Guid.NewGuid from C#. This has to work on Windows (XP, Server 2003/8, etc) and 3 different distros of Unix (AIX, Sun, ...

Variable Arity in C?

Does anyone knows how I might be able to implement variable arity for functions in C? For example, a summing function: Sum(1,2,3,4...); (Takes in a variable number of args) Thanks! ...

Counting machine instructions of a process using PTRACE_SINGLESTEP

Hi, on a Linux machine, I am using ptrace with the PTRACE_SINGLESTEP parameter to count the number of machine instructions of a program. I followed this article: http://www.ncsu.edu/it/mirror/ldp/LDP/LGNET/81/sandeep.html. However, the result seems odd to me. For a very simple program, over 95000 machine instructions are counted. The t...

How efficient is SBCL for storing big graphs?

How much does the garbage collector affect performance when working with lots of objects in memory, how big is the memory allocation and dealocation overhead? Is it wise to use SBCL to do this or is better to build a small C library to connect trough FFI? ...

Determine if C library is installed on Unix

As a follow up question to my last one, is there any simple way to tell if a given C library is installed on a given machine (not programattically, just as a once off sort of thing)? I need to use libuuid, but I'm not sure if it's installed on the machines in question. The only two ways I can think of are: 1) Try to compile the code t...

When does FTP server accept passive data connection from client?

I'm working on a simple ftp server in c. I don't know when ftp server accepts passive data connection from client. To my understanding here is how passive ftp works: client sends "PASV" command to server server creates and binds a socket, and listens on a random port. server uses getsockname to get random port assemble passive reply me...

convert ASM to C (not reverse engineer)

I googled and I see a suprising amount of flippant responses basically laughing at the asker for asking such a question. Microchip provides some source code for free (I don't want to post it here in case that's a no-no. Basically, google AN937, click the first link and there's a link for "source code" and its a zipped file). Its in AS...

C - Pthreads mutex and general headaches

Hey guys I was wondering if someone could provide a little help. I've been trying to teach myself pthreads and with that, mutex locks to get threads running together and using the same structure, whilst not reading and writing to bad data. My problem at the moment is, From my thread function, if i call a helper function that might loo...

Min Value from Stack

I have a stack which contains some integer data. I want to find out the min value from Stack in O(1) time. Any idea? PS: There is no ordering (increasing/decreasing) of data in Stack. Thanks, Naveen ...

Programmable USB dongles

Where can I buy a programmable USB dongle that supports C as a development language? ...

Specifying implementation of interface

Hi In my implementation I have a preprocessor definition that specifies the operating system the application is running on, e.g. OS_WIN or OS_LINUX. In a header file, I have defined the interface, that is the same for each operating system. //interface.h: void functionA(); void functionB(); I also have the implementations for the i...

Test printf implementation

Hi I would like to have a portable implemenation of my application. However, I have heard that there are some issues with printf from the stdlib on certain machines where it does not behave as intended. For instance, when using the conversion specifier %f then it can happen that on certain architectures the printf implementation includ...

offsetof at compile time

Is there a way of finding the offset of a member of a structure at compile-time? I wish to create a constant containing the offset of a structure member. In the following code the offsetof() macro works in the first printf statement. However, the use in line 10 to declare 'ofs' generates the error "Cannot resolve '->' operator as a const...

How can I see symbols of (C and C++) binary on linux?

Which tools do you guys use? How do demangle c++ symbols do be able to pass it to profiler tools, such as opannotate? Thanks ...

GtkGlArea's configure script is ignoring opengl32.a in MinGW

I've got a strange situation. I downloaded gtkglarea. I ran the configure script, telling it --with-lib-opengl32. This is necessary under MinGW because OpenGL is in the library c:/mingw/lib/opengl32.a. I also specified to configure that it needs to look for libraries in c:/mingw/lib using --libdir=c:/mingw/lib. And I have the library ope...

fast elapsed time on linux

Hi there, I am looking for a fast way to get the elapsed time between two calls of a function in C. I considered using jiffies, but they are not available in userland. So, should I use getimeofday() or is there any fastest way to do this. I am only interested in the elasped time between two calls, to use in a benchmark tool. ...

Is extern "C" only required on the function declaration?

I wrote a C++ function that I need to call from a C program. To make it callable from C, I specified extern "C" on the function declaration. I then compiled the C++ code, but the compiler (Dignus Systems/C++) generated a mangled name for the function. So, it apparently did not honor the extern "C". To resolve this, I added extern "...