c

Combine two 32bit efficiently? - C

I have a function which expects a 8 bytes long unsigned char. void f1(unsigned char *octets) { unsigned char i; for (i=0;i<8;i++) printf("(%d)",octets[i]); } This is how I use it while I have one 64bit integer: unsigned long long ull = 1; f1((unsigned char *) &ull); (it uses the machine's native endianness.) My questi...

Variable stack size

My system (linux kernel 2.6.32-24) is implementing a feature named Address Space Layout Randomization (ASLR). ASLR seems to change the stack size: void f(int n) { printf(" %d ", n); f(n + 1); } int main(...) { f(0); } Obviously if you execute the program you'll get a stack overflow. The problem is that segmentation fault...

Flipping sign on packed SSE floats.

I'm looking for the most efficient method of flipping the sign on all four floats packed in an SSE register. I have not found an intrinsic for doing this in the Intel Architecture software dev manual. Below are the things I've already tried. For each case I looped over the code 10 billion times and got the wall-time indicated. I'm ...

Intrusive lists

I've not been able to find too much information about them online. What are they and when are they typically used? Thanks. ...

strncmp() and if() does not agree...what am I missing?? (raw sockets)

I'm trying to build a simple echo server/client that works on ethernet level(using raw sockets). The server side by itself works and shows all incoming packets on eth0. The client works and sends ethernet packets on eth0 (I checked this with wireshark and can see the packets going out.) I now want to make a filter to only look at the p...

how to work with container components using FFmpeg?

So are there any examples\materials on how to work with containers elements using ffmpeg? GFLV "tags" for example or Mpeg atoms? ...

beanstalkd c client library

We are going to implement a fairly complex new service in an asynchronous way, introducing asynchronous processing as well. For this, we have selected beanstalkd message queue service, as it fits best for our needs. The problem is that beanstalk seems to miss client API in C, at least I have failed to find it. I do not want to invent t...

C/C++ optimization: negate doubles fast

I need to negate very large number of doubles quickly. If bit_generator generates 0, then the sign must be changed. If bit_generator generates 1, then nothing happens. The loop is run many times over and bit_generator is extremely fast. On my platform case 2 is noticeably faster than case 1. Looks like my CPU doesn't like branching. Is ...

Explain the strange assembly of empty C `main` function by Visual C++ compiler.

Hello, I just noticed some strange assembly language code of empty main method. //filename: main.c void main() { } disassembly: push ebp mov ebp,esp sub esp,0C0h; why on the earth is it reserving 192 bytes? push ebx push esi push edi ; good compiler. Its saving ebx, esi & edi v...

using stat to detect whether a file exists (slow?)

I'm using code like the following to check whether a file has been created before continuing, thing is the file is showing up in the file browser much before it is being detected by stat... is there a problem with doing this? //... do something struct stat buf; while(stat("myfile.txt", &buf)) sleep(1); //... do something else alt...

vsnprintf and gcc

Hello, I have the fallowing statement: vsnprintf(target, size - 1, "%ls_%ls", str16_1, str16_2); Do you know why this fails on gcc? I used this on Windows like this: vsnprintf(target, size - 1, "%S_%S", str16_1, str16_2); and it's working as expected. On gcc documentation I found that %S is synonym with %ls, but I must not use it...

[OpenSSL] pthread_create failed and returned -1 (or 4294967295)

Hi experts, I'm trying to reproduce an example from Network Security with OpenSSL (by Chandra et al). The program consists of client.c server.c common.h and common.c. client.c simply creates a connection to the server on port 6012 and reads data from stdin and then send those data to the server. The server.c reads data from socket and w...

g++ linking order dependency when linking c code to c++ code.

Prior to today I had always believed that the order that objects and libraries were passed to g++ during the linking stage was unimportant. Then, today, I tried to link from c++ code to c code. I wrapped all the C headers in an extern "C" block but the linker still had difficulties finding symbols which I knew were in the C object archiv...

Cost of passing variables to functions

I am unsure about how function calls are translated and I am afraid that passed variables are copied into local variables when they don't need to be. I could avoid unnecessary copying by using global variables, but that cannot be a good solution... 1) When variables are not changed in the target function, would it be better to pass them...

Assign Returned Pointer to Array

Hi, I have a function returning float* where it's actually filled as an array in the returning function such that float* some_fnc() { float *x=malloc(sizeof(float)*4); x[0]=...... } ... // in main float y[4]; y=some_fnc(); however I get an "Incompatible types" error, is it normal? Is there a way to overcome this w/o declaring...

lvalue required as increment operand

Hello, gcc 4.4.4 Maybe I am being dumb. But what am I doing wrong? char x[10]; char y[] = "Hello"; while(y != NULL) *x++ = *y++; Many thanks for any advice, ...

extract string messages from set of #define

I'm using a third party library that has a lot of different error codes. An include files contains a whole bunch of lines like: #define ABC_INVALID_BUFFER_SIZE 101 #define ABC_INVALID_COMMAND 102 etc. At runtime, I'm getting various error codes as I'm developing my application. I want to, at runtime, have the application print out me...

Linux: How to modify shared library name in Dynamic Section of an ELF binary

I have a shared library with soname: libfoo.so How do I link my binary to libfoo.so such that the shared library name in my binary's ELF section is: libfoo5.so? I tried creating a symlink: libfoo5.so -> libfoo.so, and then linking my library as such: g++ ... -o mybinary *.o -Lpath -lfoo5 However, when I print out the dynamic section...

Can this be done with OpenGL?

I'm making a vector drawing application with OpenGL. Is there a way to implement a clipping mask? Ex: if I have Circle A and Circle B, I only want to see the part of circle B which intersects into Circle A's space. Is there a way to do this that isn't very expensif, I do not want to kill my application. Thanks ...

Linux: how are .pc files used when linking against a shared library?

From my knowledge, *.pc files store metadata about shared libraries. Does the linker automatically use these files when linking against a shared library? If so, where does it search for these files? ...