c

How do I swap elements in a List?

I am trying to learn about data structures and algorithms on my own. I wrote my own double-linked list in C and now I want to write some algorithms to perform on the list. What is the preferred way to swap list items? Is it better to swap the content or to rearrange the pointers which point to the next and previous list item? ...

Why does an empty loop use so much processor time?

If I have an empty while loop in my code such as: while(true); It will drive the processor usage up to about 25%. However if I do the following: while(true) Sleep(1); It will only use about 1%. So why is that? Update: Thanks for all the great replies, but I guess I really should have asked this question, http://stackoverflow...

How to get character's position in alphabet in C language?

Is there a quick way to retrieve given character's position in the english alphabet in C? Something like: int position = get_position('g'); ...

When to use function-like macros in C

Hi, I was reading some code written in C this evening, and at the top of the file was the function-like macro HASH: #define HASH(fp) (((unsigned long)fp)%NHASH) This left me wondering, why would somebody choose to implement a function this way using a function-like macro instead of implementing it as a regular vanilla C function? Wha...

gtk treeview pix text cell renderer

I want to replace a GtkCList with GtkTreeView, but I can't seem to figure out how to accomplish the same functionality as the gtk_clist_set_pixtext function. I'm guessing I need a custom cell render. Does somebody have a free implementation I can use or am I on my owning in having to write one from scratch? ...

FIFO queue (or stack) implemented on disk, not ram (preferably in C++)

Basically what I'm after is the equivalent of the Standard Template Library queue implemented in such a way as to use the disk for storage. The volume of data that will need to be in the queue is far greater than can be stored in the ram of most computers today. Ideally, I'm after a library to use. However, any recommendation on how to ...

Inline Assembler: What scratch registers can be used?

When inserting inline assembler into a function in a C-like language, what is the convention about what registers you're allowed to use for scratch? Is it the compiler's responsibility to save the values of all the registers it needs to save before entering the asm block? Is it the responsibility of the programmer to store the values i...

How to detect LLVM and its version through #define directives?

The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version. This is part of the code I'm using: /* GNU C Compiler Detection */ #elif defined __GNUC__ #ifdef __MINGW32__ #define COMPILER "MinGW GCC %d.%...

How can an IBM WebSphere MQ's Queue Manager's local queues be enumerated?

I'm trying to write a simple tool for monitoring the state of a Queue Manager. One of the things I'd like to monitor is the current queue depth of each queue. I haven't been able to find a way to programmatically enumerate all of the queues on a particular Queue Manager, though. Do any of the MQ APIs provide this functionality? I'd p...

Given a set of points, how do I find the two points that are farthest from each other?

I could compute the distance between each point and take the largest but that doesn't sound like a very efficient way to do it when there are a large (> 1000) number of points. Note: This is for iPhone so I don't have a ton of processing power. ...

Is there a standard way to convert a struct timeval into a struct timespec?

struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec. struct timespec works the same way except that instead of microseconds it's offset (tv_nsec) is stored in nanosecond units...

How to delta encode a C/C++ struct for transmission via sockets

Hi, I need to send a C struct over the wire (using UDP sockets, and possibly XDR at some point) at a fairly high update rate, which potentially causes lots of redundant and unnecessary traffic at several khz. This is because, some of the data in the struct may not have changed at times, so I thought that delta-encoding the current C str...

How do I exec() a process in the background in C?

I've done a fork and exec() on a process, but I'd like to run it in the background. How can I do this? I can just avoid calling waitpid on it, but then the process sits there for ever, waiting to return it's status to the parent. Is there some other way to do this? ...

WCF (WCF-Binding) in/with C/C++

Is thare any like WCF libs (OpenSourse) written in C\C++? Or at least some kined of special WCF C++ services (NOT ON Basic HTTP Binding)? ...

How can I sort a linked list in C ?

Hi, Need to be able to either sort or insert entries to a linkedlist in alphabetical order. Is there a good way to do that? ...

Is C faster than C++?

I've heard many opinions on this subject, but never saw any good proofs that C is faster than C++. So, ...is C faster than C++? EDIT: This is a Runtime comparison. ...

How to check if a process with a pid X is a zombie?

I got the PID of a process and I need to check if it is a zombie using POSIX system calls in C. How should I do that? The problem I'm having is that I have a process and it forks into many children, the children all do execs and sometimes I want to do the exec in background so I can't really wait() the children that go in background. I ...

C++ sync and backup framework

Hi I'm looking for a commercial/open source backup library in C++. I have seen the Microsoft sync Framework but unfortunatly it requires the .net framework to be installed... Thank you Jonathan ...

Networking in C/C++?

I am a begginer C++ programmer. In C#, I used the System.Net.Sockets.Socket class, which represents a networking socket, to create/connect a server. How can I do the same thing in C/C++? Are there any classes like this? ...

What could be the reason for getting the error "multiple definitions" while linking?

I keep getting errors that my functions have been defined multiple times. Of course I only have one file and one function with that name in my file. Where could gcc find those other definitions? Here is an example error message, but I get many of those: /tmp/ccerCzAD.o:main.c:(.text+0xdb): first defined here /tmp/ccGbaGfJ....