c

C sizeof equivalent for macros

So I'm optimizing some code by unrolling some loops (yes, I know that I should rely on my compiler to do this for me, but I'm not working with my choice of compilers) and I wanted to do so somewhat gracefully so that, in case my data size changes due to some edits in the future, the code will degrade elegantly. Something like: typedef ...

Rolling median algorithm in C

I am currently working on an algorithm to implement a rolling median filter (analogous to a rolling mean filter) in C. From my search of the literature, there appear to be two reasonably efficient ways to do it. The first is to sort the initial window of values, then perform a binary search to insert the new value and remove the exiting ...

Difference between use C# and C or C++ on windows mobile

Hi Friend's I am new to windows mobile development. I have certain doubts related to windows mobile development which are as follows. 1) What is the major difference between C# and C (C++) as far as selecting language for development. ( not syntactically ) . 2) Which language should i select for development and Why ?? 3) If i go...

Regex matching spaces, but not in "strings"

I am looking for a regular exression matching spaces only if thos spaces are not enclosed in double quotes ("). For example, in Mary had "a little lamb" it should match the first an the second space, but not the others. I want to split the string only at the spaces which are not in the double quotes, and not at the quotes. I am usin...

How to validate a string against legal characters in standard C?

I want to validate a string against legal characters using standard C. Is there a standard functionality? As far as I can see, GNU Lib C's regex lib is not available in VC++. What do you suggest for implementing such a simple task. I don't want to include PCRE library dependency. I'd prefer a simpler implementation. ...

Program can't load after setting the setuid bit on

Consider this scenario in which an executable A.bin uses libY.so and libZ.so. A.c, Y.c and Z.c are all written in C. Z.c and Y.c are compiled into respective .so files. This is the directory structure of the files $home/bin/A.bin $home/lib/libY.so $home/lib/libZ.so When I run A.bin as normal user, A.bin runs normally as expected. Note...

Get call stack from any thread within C.

In C on Solaris 10, I'd like to get the call stack from an arbitrary thread within a process. I have many worker threads and one thread which monitors them all to detect tight loops and deadlocks. The function I'd like to implement is for the monitoring thread to print the call stack from the "hung" thread several times before it kills...

Run time Data and Code memory size estimate

Hello All, I am working on a project, C programing language, to develop an application, that can be ported on to a number of different microcontroller platforms, such as ARM\Freescale\PIC microcontroller. I am developing this application on Linux now and then I will have to port it to the above said platforms. I would like to know, are...

How to pinpoint where a long function returns

Suppose there is a function with 1000 code of line named LongFunction, and we used it: bool bSuccess = LongFunction(); assert(bSuccess); Here I got an assert when debugging, and I know there is something wrong with LongFunction, so I need to find where the function meet problems and returns: I could probably debug it step by step, i...

Identify if a file(dll/exe) is locked or not by a process or library

I'am planning to write a sample program which identifies a file (a dll file) locked by / used by some process. How can we achieve this programmatically using WIN API (a C/C++ function)? Actually, when we are performing some software upgrade process some other process might be using the library which will interim fail the upgrade operati...

CGImageRef in OS X application?

Hi, I have a .c code snipped that I don't want to port to Objective-C. This .c file worked on the iPhone platform, but not on OS X. It seems that the compiler doesn't know what to do with #import <CoreGraphics/CoreGraphics.h> and so it doesn't know CGImageRef: ImageArray3D *ia3d_createWithCGImage(CGImageRef image, int nLargestEleme...

How to retrieve the telephone number from an AT CMGL response?

I have an application written in C that reads text messages from a modem using AT commands. A typical AT response from the modem looks like this: +CMGL: 1,"REC READ","+31612123738",,"08/12/22,11:37:52+04" The code is currently set up to only retrieve the id from this line, which is the first number, and it does so using the following ...

is there any basic way to delete something from opened file...

When you open a .txt file with fopen Is there any way to delete some strings in a file without rewriting. For example this is the txt file that i will open with fopen() ; ------------- 1 some string 2 SOME string 3 some STRING ------------- i want to delete the line which's first character is 2 and change it into ------------- 1 so...

How to store the wchar value in double quotes string

hi in the below code i am getting the c:\windows\Microsoft.Net\Framework\v2.0.057 to the buffer.Now i wnat to store the above value in doble quotes " c:\windows\Microsoft.Net\Framework\v2.0.057" and i want to pass this for the process. how to make this path in double quotes.... HINSTANCE hDLL = LoadLibrary(TEXT("mscoree.dll")); FN...

Can I call a Win32 API from the Visual Studio Immediate Window?

I'm debugging a C++ Win32 application and I'd like to call an arbitrary Win32 API from the context of that process, as though the program had run this line of code: DestroyWindow(0x00021c0e); But entering that into the Immediate Window gives: CXX0017: Error: symbol "DestroyWindow" not found Edit: Using the full name of the function...

What is the Re-entrant lock and concept in general?

I am always get confused . Would someone example what Reentrant means in different contexts? And why would you want to use reentrant vs. non-reentrant. Say pthread (posix) locking primitives, are the re-entrant or not? What pitfalls should be avoided when using them Is mutex re-entrant? Thanks ...

C: dependency analysis of functions

Is there a tool where I can give a file + function name as an input and it gives me all functions the given function depends on and the same for all the found functions, and so on within my codebase? Something like this would help a lot in extracting functionality from existing codebases. ...

Detect if stdin is a terminal or pipe in C/C++/Qt?

When I execute "python" from the terminal with no arguments it brings up the Python interactive shell. When I execute "cat | python" from the terminal it doesn't launch the interactive mode. Somehow, without getting any input, it has detected that it is connected to a pipe. How would I do a similar detection in C or C++ or Qt? ...

Tiling Simplex Noise?

I've been interested (as a hobbyist) in pseudo-random noise generation, specifically the Perlin and Simplex algorithms. The advantage to Simplex is speed (especially at higher dimensions), but Perlin can be tiled relatively easily. I was wondering if anyone was aware of a tiling simplex algorithm? Fixed-dimension is fine, generic is bett...

C: char to int conversion

From The C Programming Language (Brian W. Kernighan), 2.7 TYPE CONVERSIONS, pg 43 : "There is one subtle point about the conversion of characters to integers. ... On some macines a char whose leftmost bit is 1 will be converted to a negative integer. On others, ... is always positive. For portability, specify signed or ...