c

Porting C++ lib/app on android

I want to port few C/C++ libraries to android, how feasible it would be e.g. openssl can it be ported or suppose an application which depends on openssl, what is the best way to port it to android when android i think itself has libssl.so what are the tools available e.g. scratchbox , any alternatives? Has anybody experience with it? ...

Best algorithm to strip leading and trailing spaces in C

What is the best approach in stripping leading and trailing spaces in C? ...

How do I do high quality scaling of a image?

I'm writing some code to scale a 32 bit RGBA image in C/C++. I have written a few attempts that have been somewhat successful, but they're slow and most importantly the quality of the sized image is not acceptable. I compared the same image scaled by OpenGL (i.e. my video card) and my routine and it's miles apart in quality. I've Google ...

Are there any practical applications for the format %n in printf/scanf family?

int x; printf("hello %n World\n", &x); printf("%d\n", x); ...

Calling C Code from FORTRAN

Given Microsoft FORTRAN 5.1 and Microsoft C/C++ 14.0, along with the linker that comes with that version of FORTRAN (that must be used for other dependencies) how do I create a C function and call it from the FORTRAN application? ...

How to check a value type?

How do I check the type of a value on runtime? I'd like to find out where I'm creating doubles. ...

Defining const values in C

I have a C project where all code is organized in *.c/*.h file pairs, and I need to define a constant value in one file, which will be however also be used in other files. How should I declare and define this value? Should it be as static const ... in the *.h file? As extern const ... in the *.h file and defined in the *.c file? In what...

How to use MSVC intrinsics to get the equivalent of this GCC code?

The following code calls the builtin functions for clz/ctz in GCC and, on other systems, has C versions. Obviously, the C versions are a bit suboptimal if the system has a builtin clz/ctz instruction, like x86 and ARM. #ifdef __GNUC__ #define clz(x) __builtin_clz(x) #define ctz(x) __builtin_ctz(x) #else static uint32_t ALWAYS_INLINE po...

Binary search optimization in c?

I am writing a key record look up where the I have an index between the key and the rec number. This is sorted on the key. Is there away to do this better that what I have for speed optimization? typedef struct { char key[MAX_KEYLEN]; int rec; } KeyRecPair; typedef struct { KeyRecPair *map; int numRecs; } Key...

code coverage in C

I'm looking to have code coverage in C. I cannot rely on tools like gcov as I am working on different platforms/compilers. Basically I am looking for a strategy to incorporate code coverage into my(own implementation) unit-test framework. ...

sprintf() without trailing null space in C

Is there a way to use the C sprintf() function without it adding a '\0' character at the end of its output? I need to write formatted text in the middle of a fixed width string. ...

Function like SetFileLength() in C Library for Linux

Is there a function in the C Library under Linux which can set the length of a file? Under Windows I know there is a SetFileLength() function. If there is not, what is the best way of shortening a file without deleting and rewriting it? ...

C# ANTLR grammar?

I'm looking for turn-key ANTLR grammar for C# that generates a usable Abstract Syntax Tree (AST) and is either back-end language agnostic or targets C#, C, C++ or D. It doesn't need to support error reporting. P.S. I'm not willing to do hardly any fix-up as the alternative is not very hard. ...

How to store data in variable length arrays without causing memory corruption?

This is a fairly basic question, which for some reason, a proper solution escapes me at the moment. I am dealing with a 3rd-party SDK which declares the following structure: struct VstEvents { VstInt32 numEvents; ///< number of Events in array VstIntPtr reserved; ///< zero (Reserved for future use) VstEvent* events[2]; //...

Interop'ing between C# and an unmanaged C library

I have a small C library in a DLL and I need to call a handful of its methods. It uses pointers and a few structs but is otherwise quite simple. Problem is I'm not terribly knowledgable on .NET's interop with the unmanaged world and my attempts so far keep hitting memory access violation exceptions (presumably due to me not getting the ...

How do you handle large data transfers on very memory constrained, embedded systems?

I have a microcontroller that must download a large file from a PC serial port (115200 baud) and write it to serial flash memory over SPI (~2 MHz). The flash writes must be in 256 byte blocks preceded by a write command and page address. The total RAM available on the system is 1 kB with an 80 byte stack size. This is currently working ...

Why does the following print 'Resource temporarily unavailable'?

Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time? That is the EAGAIN code, which is the same as WOULD BLOCK which means there is no data waiting to be read, but select is returning 1 saying there is data (tested in Linux): #include <time.h> #include <unistd.h> #include <stdio.h> #include <stri...

What's wrong with this memory allocation

Hi guys, I tried to make a dynamic 2D array of char as follow: char** ppMapData = (char**)malloc(sizeof(char*)*iMapHeight); for (int i=0; i< iMapHeight; i++) { ppMapData[i] = (char*)malloc(sizeof(char)*iMapWidth); //do something } // do something for (int i=0; i<iMapHeight; i++) free(ppMapData[i]); free(ppMapData); It lo...

How to measure time in milliseconds using ANSI C?

Using only ANSI C, is there any way to measure time with milliseconds precision or more? I was browsing time.h but I only found second precision functions. ...

Learning x64 on a linux system

I am looking for some good resources on x64 assembly on a linux system, in order to write code myself. I am also looking for some introductory notions like memory spaces (stack, heap, etc.). I found a good free book online, Programming From the Ground UP, the trouble is, it is targeted at x32 linux systems. I also played a lot with gcc -...