c

When sending an array of int over TCP, why are only the first amount correct?

Following my previous question (Why do I get weird results when reading an array of integers from a TCP socket?), I have come up with the following code, which seems to work, sort of. The code sample works well with a small number of array elements, but once it becomes large, the data is corrupt toward the end. This is the code to send ...

How do I convert utf8 to/from utf16 in C?

Is there a library available or do I need to design/code my own? The target platform is very old and the compiler does not provide wchar_t. No library allowed so plain c/headers will be appropriate ...

Struggling with C coming from Object Oriented land?

When I am presented with programming problems, I naturally start breaking them up into logical objects in my head. Who has what responsibility, who owns what, who derives from what, etc. I am struggling with C. I just don't get how to do things in a Procedural Language. Can an experienced C programmer help explain how I should thin...

Interpreting error code from apr_dso_load()

In a team environment on a Linux system I just pulled the latest code base from the head of the tree, and some stuff that's been working for a long time has stopped working. We have dynamic shared objects, and the APR library call faills: err = apr_dso_load(&mod->handle, mod->path, mod->pool); if (err ) { fprintf (stderr, "Faile...

Performance hit from C++ style casts?

I am new to C++ style casts and I am worried that using C++ style casts will ruin the performance of my application because I have a real-time-critical deadline in my interrupt-service-routine. I heard that some casts will even throw exceptions! I would like to use the C++ style casts because it would make my code more "robust". Howeve...

Trouble compiling dll that accesses another dll.

So, I have an interesting issue. I am working with a proprietary set of dlls that I ,obviously, don't have the source for. The goal is to write an intermediate dll that groups together a large series of funnction calls from the proprietary dlls. The problem I am having, when compiling with g++, is that I get errors for the original dl...

Successive calls to recvfrom() loses data?

I am working on a reliable file transfer program that uses UDP. (for a course in computer networking.) My question is this - well, consider this scenario: Sender has (for example) 12 bytes of data to send. So the sender performs this call: sendto(fd, &buf, 12, 0, (struct sockaddr *)&cliaddr,sizeof(cliaddr)); This sends the 12 bytes...

How to properly insert/delete in a binary search tree in C?

I kinda have to put my previous C questions on hold cause this one is more important now... I have already coded the insert and delete functions on my binary search tree but the delete function is incomplete. There's a couple of things I need help in... 1) Is my insert function good or can it be improved somehow? 2) My delete function...

setjmp/signal crash exception handling

I am trying to install a "crash handler" for a C OSX Carbon multithreaded application. On Windows, I can easily use the simple and efficient try{} __except{} SEH of Windows which works great. (Note these are **unrelated to C++ exceptions, these are lower level C constructs!) This is very related to a question I asked on SO previously: ...

Fast way to implement 2D convolution in C

I am trying to implement a vision algorithm, which includes a prefiltering stage with a 9x9 Laplacian-of-Gaussian filter. Can you point to a document which explains fast filter implementations briefly? I think I should make use of FFT for most efficient filtering. ...

C convert hex to decimal format

Hello, Compiling on linux using gcc. I would like to convert this to hex. 10 which would be a. I have managed to do this will the code below. unsigned int index = 10; char index_buff[5] = {0}; sprintf(index_buff, "0x%x", index); data_t.un32Index = port_buff; However, the problem is that I need to assign it to a structure and t...

What source files can I read for learning C?

I want to learn C languages and I'm running a Linux distro (Ubuntu) so I would like to know where can I begin? I know some people will tell me to read K&R books or others but I want to pratice C, not theory. So I believe that reading C sources and changing some words will help me to understand. So what are the sources for a beginner? ...

Where has asm/timex.h and get_cycles() gone?

In an older linux distro I could call get_cycle() after including asm/timex.h. Now I changed to Kubuntu 9.04 and there is no asm/timex.h, plus in sys/timex.h there is no get_cycle(). Does anyone know why this changed, how to access this fuction/macro or a replacement for it? Or, even better, where to read information about it? Thanks in ...

Fastest method for checking overflow?

Here's my attempt. Any tips on a better solution?: // for loop to convert 32 to 16 bits uint32_t i; int32_t * samps32 = (int32_t *)&(inIQbuffer[0]); int16_t * samps16 = (int16_t *)&(outIQbuffer[0]); for( i = 0; i < ( num_samples * 2/* because each sample is two int32 s*/ ); i++ ) { overflowCount += ( abs(samps32[i]) & 0xFFFF8000 ) ?...

Why is my C++ code causing a segmentation fault well after using the read(...) function?

My application is suspending on a line of code that appears to have nothing wrong with it, however my IDE appears to be suspending on that line with the error: gdb/mi (24/03/09 13:36) (Exited. Signal 'SIGSEGV' received. Description: Segmentation fault.) The line of code simply calls a method which has no code in it. Isn't a segment...

How to avoid code duplication between similar ISRs?

I have two interrupt service routines (ISR) which basically do the exact same thing but each handles an interrupt from a different device (although the same type of device). Therefore, the logic is the same but they access different CPU registers and memory locations. As a simple example consider the following code: extern volatile uns...

C function conflict

What should I do if I have two libraries that provide functions with equivalent names? ...

Get Daylight Saving Transition Dates For Time Zones in C

In C, is there a simple, cross-platform way of retrieving the dates that a given timezone begins and ends daylight saving? I already have timezone offset information and whether or not daylight savings is currently being observed, but I really need the dates at which daylight savings begins and ends (for an external dependency I don't...

Some random C questions (ascii magic and bitwise operators)

Hi, I am trying to learn C programming, and I was studying some source codes and there are some things I didn't understand, especially regarding Bitwise Operators. I read some sites on this, and I kinda got an idea on what they do, but when I went back to look at this codes, I could not understand why and how where they used. My first ...

Semaphore queues

I'm extending the functionality of a semaphore. I ran into a roadblock when I realized I don't know the implementation of an actual semaphore and to make sure my code ran correctly, I needed to know this. I know a semaphore works by blocking threads that are waiting on it when they call sem_wait() and another thread currently has it lo...