c

Does GCC protect programmer from multiple including of C's library headers?

Is there a guarantee that each library header looks something like that? #ifndef STDIO_H #define STDIO_H /* contents here... */ #endif Can you please refer me to a source? Thanks! ...

How do I feed OpenSSL random data for use in ECDSA signing?

I want to feed OpenSSL specific data for use as random seed during the signing of data with an EC key. I'm doing this to compare my application with another reference one (closed source). That utility takes the file with private key, file with data to sign and file with random data as parameters. I've got the generation of EC keys, and ...

How to get the absolute path of a file programmatically with out realpath() under linux?

I know it is possible to get an absolute path of a file with realpath() function. However, according to BUGS section the manpage, there are some problem in its implementation. The details are following: BUGS Avoid using this function. It is broken by design since (unless using the non-standard resolved_path == NULL feature) it is ...

what is the unsigned datatype?

I've seen this unsigned "typeless" type used a couple of times, but never seen an explanation for it. I suppose there's a corresponding signed type. Here's an example: static unsigned long next = 1; /* RAND_MAX assumed to be 32767 */ int myrand(void) { next = next * 1103515245 + 12345; return((unsigned)(next/65536) % 32768); } v...

Prototype for function that allocates memory on the heap (C/C++)

Hi all, I'm fairly new to C++ so this is probably somewhat of a beginner question. It regards the "proper" style for doing something I suspect to be rather common. I'm writing a function that, in performing its duties, allocates memory on the heap for use by the caller. I'm curious about what a good prototype for this function should...

Linux mmap() error

I have a memory mapped file, from which I wish to parse the contents of the buffer. The mmap() returns success, and I can print out the buffer contents to a file using fprintf successfully. However, when I try to access the buffer as an array in my program directly, I get a segmentation fault. Why is this happening? Here is the code: ...

How to enumerate bound UDP / TCP sockets on Windows in C

Assuming that you do not have access to the SOCKET handlers. ...

Is there a standard mysql connection pooling library for C?

I have a C application using the MySQL library for database access. Is there a standard way to implement database connection pooling for such an application? The C connector doesn't appear to support it. ...

Optimal C Structure definition

Hi, I was just wondering about the considerations to be followed while packing items (int, float, unions, etc) in a C structure (C struct definition ) that would allow the compiler to further optimize it. I would like to know whether there are any guidelines that one should follow e.g. adding items to the structure in an order that wo...

Terminate a process tree (C for Windows)

This has been asked before but I can't find a definitive answer, in code. I open a process, ProcessA (with PID 1234). This process opens a child process, ProcessAB (PID 5678). After I'm done I terminate ProcessA but I still have the lingering of ProcessAB. How do I terminate the whole process tree? What I mean, how do I make sure that ...

Library for the Basic Data Structures, such as Queue, in C

Post related to the question here. Problem: to find the right data structure for the queue: #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <time.h> int m...

Converting between timezones in C

Hello All, I need to convert time between timezones in C (on linux, so anything specific would do too). I know my current time, local and UTC, I have the offset of the target time. I am trying to use mktime, gmtime, localtime and similar set of functions but still can't figure it out. Thanks in advance. ...

Laptop Battery Status?

Is there any way to get the status of the Battery (charging/discharging/Current Charge/Capacity/etc...) from a C++ program in a portable manner between Windows & Linux. I'm doing a small program for my own use and require some help with it. Kindly look over the description of the program on my blog: The JB Journals Also, is there any...

C development on Windows

What is a good toolset for doing C cross platform development on Windows? ...

mqueue.h not found

Hi all In one of my application, I am using "mqueue.h". I was able to compile and execute it. But one of our customer to whom I released the code, is complaining something like * mqueue.h is not found * He has not attached the exact error message though. In my linux PC, it is available in /usr/include. Can anyone guess any reason why ...

In C, which is faster: if with returns, or else if with returns?

Is it better to have if / else if, if every block in the if statement returns, or is it better to have a chain of ifs? To be specific, which if fastest: A: if (condition1) { code1; return a; } if (condition2) { code2; return b; } //etc... B: if (condition1) { code1; return a; } else if (condition2) { code2; return b;...

Bits representation of negative numbers

Hi, This is a doubt regarding the representation of bits of signed integers. For example, when you want to represent -1, it is equivalent to 2's complement of (+1). So -1 is represented as 0xFFFFFFF. Now when I shift my number by 31 and print the result it is coming back as -1. signed int a = -1; printf(("The number is %d ",(a>>31));//...

What is the recommended way to write this sql statement?

Hi , What's better way to format following sql statement considering both readability and performance. Thanks. sql = (char *)" SELECT * ,rowid FROM tblEvent_basic " " WHERE " " service_id = ? AND " " (" " (start_time >= ? AND start_time <= ?) OR " ...

What's the best way to check if you C code has deprecated POSIX calls?

I've been working on some older C code. I found out that there are quite some POSIX calls that are now outdated and marked deprecated in the manual pages. What's the best way to check if there are still deprecated POSIX calls in your code? I'm thinking of either: special gcc warning options. some kind of lint tool detecting these call...

Shared libraries and .h files

I have some doubt about how do programs use shared library. When I build a shared library ( with -shared -fPIC switches) I make some functions available from an external program. Usually I do a dlopen() to load the library and then dlsym() to link the said functions to some function pointers. This approach does not involve including any...