Is there any portable way of doing branch prediction hints? Consider the following example:
if (unlikely_condition) {
/* ..A.. */
} else {
/* ..B.. */
}
Is this any different than doing:
if (!unlikely_condition) {
/* ..B.. */
} else {
/* ..A.. */
}
Or is the only way to use compiler specific hints? (e.g....
How exactly can I do a Z buffer prepass with openGL.
I'v tried this:
glcolormask(0,0,0,0); //disable color buffer
//draw scene
glcolormask(1,1,1,1); //reenable color buffer
//draw scene
//flip buffers
But it doesn't work. after doing this I do not see anything. What is the better way to do this?
Thanks
...
Seeking to clarify something.
It is my understanding that with regard to arithmetical, logical bitwise shifts:
<< work the same for both
>> shifts differ in which logical shift will always pad byte with 0, whereas arithmetical shift will pad it with the sign bit.
How can i differentiate this using C?
From what i understand, actual...
What are the reasons that an exec (execl,execlp, etc.) can fail? If you make a call to exec and it returns, are there any best practices other than just panicking and calling exit?
...
Under Linux what would be the best way for a program to restart itself on a crash by catching the exception in a crashhandler (for example on a segfault)?
...
Suppose you have 2 numbers:
int x = 1;
int y = 2;
Without worrying about specific difference between them, i'd like to know whether x is larger then y using only bitwise operators.
I can check to see if number is positive or negative by using !(x >> 31), but before i get there, i need to implement negation using bitwise operators.
...
And, what has your experience been? Do you think that Maven has been well suited to your project, and how would you advise others on following your path?
Thanks in advance!
...
Recently I reviewed some C code and found something equivalent to the following:
struct foo {
int some_innocent_variables;
double some_big_array[VERY_LARGE_NUMBER];
}
Being almost, but not quite, almost entirely a newbie in C, am I right in thinking that this struct is awfully inefficient in its use of space because of the arr...
I have the following files: a.h, a.c, b1.c, b2.c and in both b1 and b2 I have some macro definitions which are identical.
Is it ok if I move them in a.h or is it more common to leave them in the file where they are being used ? Which way is the proper way to do it in C ?
...
Hi,
which visual studio project type should i choose that will best for c basic library(uni studies).
the problem in visual studio 2010 express that its gives _tmain instead int main().
Thanks
...
Hi,
why do i get error: 'strcmp': identifier not found in visual studio 2010 C++ Express
#include <string.h>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("%d",(int)strcmp( "str1", "str2" ));
return 0;
}
Thanks
...
I have a legacy C Linux application that I need to reuse . This application uses a lot of global variables. I want to reuse this application's main method and invoke that in a loop. I have found that when I call the main method( renamed to callableMain) in a loop , the application behavior is not consistent as the values of global varia...
This is probably something very simple but I'm not getting the results I'm expecting. I apologise if it's a stupid question, I just don't what to google for.
Easiest way to explain is with some code:
int var = 2.0*4.0;
NSLog(@"%d", 2.0*4.0);//1
NSLog(@"%d", var);//2
if ((2.0*4.0)!=0) {//3
NSLog(@"true");
}
if (var!=0) {//4
N...
Hey guys, I was working on some particle systems and this was the only way I could figure out to set up the arrays:
if (vertices){
free(vertices);
}
if (textures){
free(textures);
}
vertices = malloc(sizeof(point3D) * 4 * [particles count]);
textures = malloc(sizeof(point2D) * 4 * [particles count]);
The particles constantly ...
Hello,
I am working on an algorithm that performs a global thresholding of an 8-bit grayscale image into a 1-bit ( bit packed, such that 1 byte contains 8 pixels ) monochrome image. Each pixel in the Grayscale image can have a luminance value of 0 - 255.
My environment is Win32 in Microsoft Visual Studio C++.
I am interested in optim...
Is there software that can help create flow charts, class diagrams etc to help software development planning.
Thanks
...
For my systems programming class we're doing a lot of programming in C and are required to error check most functions as we are currently learning to program with pthreads.
The reason I say this is not really homework, is that it is far above and beyond what is expected for this class. Simply checking each function individually is more ...
I thought pthread uses clone to spawn one new thread in linux. But if so, all of the threads should have their seperate pid. Otherwise, if they have the same pid, the global variables in the libc seem to be shared. However, as I ran the following program, I got the same pid but the different address of errno.
extern errno;
void*
f(void...
Similar to this question, I'd like to limit the execution time of a function--preferably with microsecond accuracy--in C. I imagine that C++ exceptions could be used to achieve a result similar to this Python solution. Though it's not ideal, such an approach is wholly unavailable in plain C.
I wonder, then, how might I interrupt the exe...
Hey everyone, sorry for the newbie question, but I'm just starting to learn the C programming language. I've written this simple piece of code that converts the USD to Euros. Only problem is that once the input of the USD is inputed, the program just hangs. I'm using a while loop to ask the user whether or not they want to redo the op...