c

Ignore "initialization from incompatible pointer type" warnings?

Is there a compiler directive in order to ignore the "initialization from incompatible pointer type" warnings in Hardware_MouseDrivers_GPM_Methods and Hardware_MouseDrivers_DevInput_Methods? Turning off warnings globally is not an option though. #include <stdio.h> /* Mouse driver interface */ typedef struct _Hardware_MouseDriver { ...

aio_write on linux with rtkaio is sometimes long

I'm using async io on linux with rtkaio library. In my tests everything works perfectly, but, in my real application i see that aio_write which is supposed to return very fast, is very slow. It can take more than 100 milis to write a 128KB to a O_DIRECT padded file. Both my test and the application use same I/O size, i check on the same ...

accessing internal memory of the ARM from a user process on GNU/Linux

Due to some requirements on speed, we need to some computation in-place on internal memory and then DMA the results of the computation to a external memory. The application runs on a TI DM355 processor which is based on ARM926EJ-S core and a set of TI periferals (EDMA, video accelerators etc). How cleanly can this be done from the appli...

What is the preferred unit testing tool for C development in Visual Studio?

What is the preferred unit testing tool for C development in Visual Studio? ...

Why do you prefer char* instead of string, in C++?

I am a C programmer,now trying to write c++ code.I heard string in C++ was better than char* in terms of security, performance, etc,but sometimes it seems that char * is better choice.Someone suggest that programmer should not use char * in C++ becuase we could do all things that char * could do with string, and its securer and faster. ...

Calling C like callback within a thread

Hi; I have a C static library with, A callback definition: typedef void (*HandleEvents) (enum events eventID, int msgSize, char *msg); A function in the library: int init(HandleEvents _handleEvents) And another C++ GUI developed in VS. which links this static lib and calls init function of the lib giving a function pointer. ini...

Conversion specifier of long double in C

The long double data type can have these conversion specifiers in C: %Le,%LE,%Lf,%Lg,%LG (reference). I wrote a small program to test : #include <stdio.h> int main(void) { long double d = 656546.67894L; printf("%.0Le\n",d); printf("%.0LE\n",d); printf("%.0Lf\n",d); printf("%.0Lg\n",d); printf("%.0LG\n",d); return 0; } ...

Converting string containing localtime into UTC in C

I have a string containing a local date/time and I need to convert it to a time_t value (in UTC) - I've been trying this: char* date = "2009/09/01/00"; struct tm cal = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL}; strptime(date, "%Y/%m/%d/%H", &cal); time_t t = mktime(&cal); but the time_t value I get back is the value that I would expect if ...

'Safe' DLL Injection

Not a terribly good question, sorry. I have a program that needs to be alerted when a file is opened from explorer (i.e. ShellExecute(A/W) is called). Unfortunately, Microsoft removed the COM interface (IShellExecuteHook) that allows you to hook these events in Vista and up, supposedly because older code could cause a crash due to chan...

Adding a sliding sound to a website

I would like to add an unusual feature to a website that would allow the user to play a sound...a single sampled note. When the user moves a slider control the sound would go up or down in tone (seamlessly). So, as the user slides the button to the right the sound would rise in pitch, when moved to the left it would go down in pitch (fro...

fcntl() for thread or process synchronization?

Is it possible to use fcntl() system call on a file to achieve thread/process synchronization (instead of semaphoress)? ...

Why Win32 HeapReAlloc() changes values?

Hi there! I'm writing an app in C using win32 API. When I try to enlarge the size of my array, using the HeapRealloc() function, it changes my current values in the array, instead of copying them. The code I use to reallocate memory: BOOL ChangeFeedArraySize(UINT newSize) { char tempChar[20] = ""; PFEED tempArr; if (newSi...

correctly declaring the main() function in ANSI C

The C standard say: The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or with two parameters (referred to here as argc and argv, though any names may b...

Unable to locate definition of etext , edata , end

This is a code from linux man page.... #include <stdio.h> #include <stdlib.h> extern char etext, edata, end; int main(int argc, char *argv[]) { printf("First address past:\n"); printf(" program text (etext) %10p\n", &etext); printf(" initialized data (edata) %10p\n", &edata); prin...

Differences in code between Windows 32 bits and 64 bits

I was experimenting with the following code to simulate GetProcAddress. // Retrieve NT header from base address. IMAGE_NT_HEADERS *GetNtHeaderFromBase( void *pBaseAddr ) { IMAGE_DOS_HEADER *pDosHeader; IMAGE_NT_HEADERS *pNtHeaders; pDosHeader = ((IMAGE_DOS_HEADER *)pBaseAddr); if(pDosHeader->e_magic != 0x5A4D) return ...

Convert a summer date to utc in the winter?

The function mktime takes a struct tm as argument. One of the members of struct tm is tm_isdst. You can set this to 1 for wintertime, 0 for summertime, or -1 if you don't know. However, if during winter, you try to convert 2009-09-01 00:00, mktime fails to see that although it is currently winter, the date you are converting is summert...

Why does this compile with the Dev-C++ compiler and not Visual Studio's one ?

Why does the following code compile with the Dev-C++ compiler and not with Visual Studio? Any idea? Here is the code: #include<stdio.h> main(){ int n,i; scanf("%d",&n); int arr[n]; for(i= 0 ; i <n ; i++) { //Do something with the array } fflush(stdin); getchar(); } Here are the errors: ...

Bit Hack - Round off to multiple of 8

can anyone please explain how this works (asz + 7) & ~7; It rounds off asz to the next higher multiple of 8. It is easy to see that ~7 produces 11111000 (8bit representation) and hence switches off the last 3 bits ,thus any number which is produced is a multiple of 8. My question is how does adding asz to 7 before masking [edit] prod...

Opening a file with path in malloc

I'm trying to open a file with fopen, but I don't want a static location so I am getting the string in from the user when he/she runs the program. However if a user does not enter one a default file is specified. Can I just put the malloc var in to the fopen path parameter? char *file_path_mem = malloc(sizeof(char)); if (file_path_mem ...

Initialize a structure with an array in a variable

How can we initialize a structure with an array (using its variable)? This version works well: MyStruct test = {"hello", 2009}; But this version is bugged: char str[] = "hello"; MyStruct test = {str, 2009}; ...