c

What's a binary file and how do I create one?

I would like to create a binary file representing an integer. I think the file should be 4 bytes. I use linux. How to do that? Another question: How do I assign the content of that file to an integer in C? ...

How to create a lightweight C code sandbox?

I'd like to build a C pre-processor / compiler that allows functions to be collected from local and online sources. ie: #fetch MP3FileBuilder http://scripts.com/MP3Builder.gz #fetch IpodDeviceReader http://apple.com/modules/MP3Builder.gz void mymodule_main() { MP3FileBuilder(&some_data); } That's the easy part. The hard part is I...

C equivalent to Arrays.sort from Java - qsort? (How do i find the nature of its implementation)

Hi All, I'm fairly new to the C programming language but I know that it is not standardized in the same way as Java. When performing a comparisson of the runtime of a algorithm, to keep the analysis fair, I need to call a method similar to Java's Array.sort(int []). void qsort(void *base, size_t nmemb, size_t size, int (*compar)(cons...

How to hide an external program's windows programmatically?

I want to hide an external application, ie. not the current application. I want to give the title of the application and it will be hidden. How can I do this programmatically? ...

Efficient (cycles wise) algorithm to compute modulo 25?

Hi, I have a code in which i am computing x % 25. x always takes a positive value but its dynamic range is large. I found out that this particular code piece of computing a x % 25 is taking large cycles. I need to optimize it. Pre-computed lookup table is ruled out due to the possible large memory size of the table. As second appro...

Passing multi-param function into a macro

Why does this not compile on VC 2005? bool isTrue(bool, bool) { return true; } void foo(); #define DO_IF(condition, ...) if (condition) foo(__VA_ARGS__); void run() { DO_IF(isTrue(true, true)); // error C2143: syntax error : missing ')' before 'constant' } Running this through the preprocessor alone outputs: bool isTrue(bo...

C Programming: Debugging with pthreads

One of the hardest things for me to initially adjust to was my first intense experience programming with pthreads in C. I was used to knowing exactly what the next line of code to be run would be and most of my debugging techniques centered around that expectation. What are some good techniques to debugging with pthreads in C? You can s...

C/C++ Identify the digits in a given number.

Hello everyone, i'm new to programming.. and i'm stuck at a problem.. I want my program to identify the separate digits in a given number, like if i input 4692, it should identify the digits and print 4 6 9 2. And yeah, without using arrays.. Thanks in advance! ...

Volatile semantics in C99

I have an issue with some low level code I am writing, I need to use objects as volatile, but it is not necessarily so that I want the types to be declared as volatile (for reusability reasons). I can however define pointer to a qualified variant of a structure as detailed in the following segment. struct x { int bar; }; struct x foo...

toggle two bits with a single operation in C?

Lets say I have a byte with 6 unknown values: ???1?0?? and I want to swap bits 2 and 4 (without changing any of the ? values): ???0?1?? But how would I do this in one operation in C? I'm performing this operation thousands of times per second on a microcontroller so performance is the top priority. EDIT It would be fine to "toggle...

What does __sync_synchronize do?

I saw an answer to a question regarding timing which used __sync_synchronize(). What does this function do? And when is it necessary to be used? ...

abs function in C

Hi people! I wrote some code in C (not in C++): Mask1 = abs(Area1 * 2 + Area2 * -2); Area1, Area2 and Mask1 are three double variables. (e.g. 3.00556, 34.3333) My problem is that abs returns an integer value (e.g 30). What I need to do to fix it? Regards. ...

linked list

Hello, I am creating a linked list as in the previous question I asked. I have found that the best way to develop the linked list is to have the head and tail in another structure. My products struct will be nested inside this structure. And I should be passing the list to the function for adding and deleting. I find this concept confus...

Strange code error

This is regarding the problem which I posted earlier today. I made the program to identify and print the digits of a given number. The program runs fine when I use 1, 2, 4 digits (I made 4 max), but when I input a 3-digit number, it prints the numbers wrong and ends abruptly. Help me out.. #include <stdio.h> #include <stdlib.h> #includ...

How to make your embedded C code immune to requirement changes without adding too much overhead and complexity?

In many embedded applications there is a tradeoff between making the code very efficient or isolating the code from the specific system configuration to be immune to changing requirements. What kinds of C constructs do you usually employ to achieve the best of both worlds (flexibility and reconfigurabilty without losing efficiency)? If...

splitting a full filename into parts

I am creating a function that will split a full unix filename(like /home/earlz/test.bin) into its individual parts. I have got a function, and it works for the first two parts perfect, but after that it produces erroneous output... strlcpy_char will copy a string using term as the terminator, as well as 0. If it is terminated with term...

Why use C?

Why is C used for writing drivers and OS codes? Is there a size problem? Are there any drivers written in other languages? Which language were XP, Vista, and Solaris written in? ...

What is the possible use for "#define for if (false) {} else for"?

In another question, I just spotted this little pearl of C wisom: #define for if (false) {} else for which caused MSVC to spit out "constant expression" warnings for a quite valid statement: for (int i = 0; i <= 10; i++) {...} I understand why MSVC is complaining because it expands to: if (false) {} else for (int i = 0; i <= 10; i...

What is the purpose of fork()?

In many programs and man pages of Linux, I have seen code using fork(). Why do we need to use fork() and what is its purpose? ...

how to define a crypto library for xmlsec..

I want to write XML signature verification code in C using any available open source libraries.I am trying to use xmlsec. I installed the dependency libraries mentioned in http://www.zlatkovic.com/libxml.en.html. but when I try to compile the example code given in http://www.aleksey.com/xmlsec/api/xmlsec-notes-verify-x509.html , I am get...