C++ Optimization on negative integers
Lets say we have a negative integer say int a; is there a faster implementation of -a? Do I have to do some bitwise operation on this? ...
Lets say we have a negative integer say int a; is there a faster implementation of -a? Do I have to do some bitwise operation on this? ...
I'm having a strange problem. I have the following code: dbg("condwait: timeout = %d, %d\n", abs_timeout->tv_sec, abs_timeout->tv_nsec); ret = pthread_cond_timedwait( &q->q_cond, &q->q_mtx, abs_timeout ); if (ret == ETIMEDOUT) { dbg("cond timed out\n"); return -ETIMEDOUT; } dbg calls gettimeofd...
Hi, I have little more than beginner-level C skills and would like to know if there are any de facto "standards" to structure a somewhat complex application in C. Even GUI based ones. I have been always using the OO paradigm in Java and PHP and now that I want to learn C I'm afraid that I might structure my applications in the wrong wa...
Is there a simple tutorial for me to get up to speed in SSE, SSE2 and SSE3 in GNU C++? How can you do code optimization in SSE? ...
I wanted to know how the following works @ compiler level. int const iVal = 5; (int&)iVal = 10; A bit of m/c or compiler level answer would be great full. Thanks in advance. ...
I have a C code and I want to use this in C#. Is there a possibillity except rewriting this code? ...
How we can implement our own timer function in Windows without using Library functions? Should we deal with assembly language instructions? ...
I'm using the Windows API SendInput() call to simulate keyboard events. The following snippet (irrelevant details omitted) works perfectly for sending a sequence of characters: wchar_t txt = ...; INPUT *input = ...; size_t nInput = 0; for (unsigned int j = 0; j < length; j++) { input[nInput].ki.wVk = 0; input[nInput].ki.wScan ...
Using apache on a windows server with mod_fastcgi, the C code looks like that: void main() { init(); while (FCGI_Accept() >= 0) work(); cleanup(); } When the service is taken down (i.e.: net stop apache2), the process terminates without getting to the cleanup code. What am I missing here? ...
We have a third party device we are trying to integrated into our system and one of the things our code should do is start a hardware reset by asserting a reset pin. One of the documents mentions the pin being released before the end of POR. I bit of Google has given me this but I just wanted to confirm and understand if I am on the corr...
Hi, I will begin to use C for an Operating Systems course soon and I'm reading up on best practices on using C so that headaches are reduced later on. This has always been one my first questions regarding arrays as they are easy to screw up. Is it a common practice out there to bundle an array and its associated variable containing...
I have a legacy firmware application that requires new functionality. The size of the application was already near the limited flash capacity of the device and the few new functions and variables pushed it over the edge. Turning on compiler optimization does the trick, but the customer is wary of doing so because they have caused failure...
I am making an old-school 2d game, and I want to animate a specific color in my texture. Only ways I know are: opengl shaders. animating one color channel only. white texture under the color-animated texture. But I don't want to use shaders, I want to make this game as simple as possible, not many extra openGL functions etc.. And t...
I have the method below, and it correctly sets the ret value to 0 (indicating success in setenv), but when I check to see if this environment variable is actually set, it's absent. Why would this be happening? void Class::mysetenv(char* a, char* b) { if(a==0 || b==0) return; ...
Duplicate: Good Programming Practices for Macro Definitions (#define) in C C (and by extension C++) macros are laden with pitfalls and practical problems when not implemented properly. Take, for example, the macro #define cube(x) x*x*x What is wrong with it? Where will it fail? When can unexpected results be returned? What is ...
I'm writing some optimized C code that basically runs through an array and does something to each element. What it does depends on the current value of the element so something like: for (i=0; i < a_len; i++) { if (a[i] == 0) { a[i] = f1(a[i]); } else if (a[i] % 2 == 0) { a[i] = f2(a[i]); } else { a[i...
If I create a DIB using CreateDIBSection(), I can specify wether it should be top-down or bottom-up by setting the biHeight field of the BITMAPINFOHEADER struct to a negative or positive value. However, if i call GetObject() on such a bitmap to fill a DIBSECTION structure, then both the dsBm.bmHeight and dsBmih.biHeight seem to be always...
Hello, I have some code that stack dumps when using sprintf to copy a a pointer to strings. I am trying to copy the contents of animals into a new pointer array called output. However, I get a stack dump. What should be in the output is the following: new animal rabbit new animal horse new animal donkey An I going about this the right...
Hello, I am currently designing a font engine for an embedded display. The basic problem is the following: I need to take a dynamically generated text string, look up the values from that string in a UTF-8 table, then use the table to point to the compressed bitmap array of all the supported characters. After that is complete, I call...
I wrote a C program in which I did some pretty heavy stack allocation, around 2 MiB. Since I use the poor man's IDE* I was automatically running the program via make in order to test it, each time I compiled. I had pretty much wrapped everything up, but for some reason, during some of the final optimization, I ran it directly from the s...