Consider a simple (global in my case) variable:
int i;
Somewhere this variable is accessed
pthread_mutex_lock(i_mutex);
if(i == other value) {
do_something();
}
pthread_mutex_unlock(i_mutex);
Another thread updates i while it holds i_mutex . Could the compiler cache the value of i so
I don't get the recent value ? Must i be vola...
I'm trying to get some c & ASM sample code I found running in Visual Studio 2008. I don't think the problem is the difference between VS 2005-2008. This example is supposed to get the CPUID on 64-bit systems. (My attempts getting the ASM-only 32-bit examples to compile failed too)
I can copy and paste this code into a new project, bu...
How can i get system idle time (no keys pressed - mouse moved) in C or Python?
EDIT: My program suspend a counter when idle time > 10 sec
...
I'm using C (not C++) and I'm unsure how to avoid using global variables.
I have a pretty decent grasp on C, its syntax, and how to write a basic application, but I'm not sure of the proper way to structure the program.
How do really big applications avoid the use of global variables? I'm pretty sure there will always need to be at lea...
I was told this is a buggy code, but I don't know why, some could explain it to me.
why there would not be an array out of bound exception when I compile?
int a[10];
int j;
void main () {
int i, j = 42;
for (i = 0; i <=10; i++) a[i] = i;
printf("%d", j);
}
...
How do I find the vertices of the broken line that surrounds the silhouette in this image?
A possible input for the example above is:
WIDTH HEIGHT POSITION
3 9 17
5 9 9
12 4 8
3 11 3
10 7 1
2 3 19
So for this example the solution would be
[(1, ...
Hi I have the following union which is part of a larger struct and I want to store a uint64_t (64 bits size) data in this union. However i want to store it by accessing the id_data field since the others are not large enough for a complete uint64_t. But i dont know how to assign my uint64_t data into this id_data field.
I know how to ...
In C programming, whenever I try to perform first time cat, I need to
TCHAR file_name[1024];
// Use memset or set the first byte to 0?
file_name[0] = 0;
_tcscat(file_name, TEMP_DIRECTORY_PATH);
_tcscat(file_name, file);
I see most programmers are using memset. But, for me, I just set the first byte to 0, to let _tcscat knows where to ...
I want to load a txt file into an array like file() does in php. I want to be able to access different lines like array[N] (which should contain the entire line N from the file), then I would need to remove each array element after using it to the array will decrease size until reaching 0 and the program will finish. I know how to read t...
function()
{
FILE *ptr;
ptr = fileopen(file1.txt)
fprint(ptr, some text) //print to file 1
if(second file needed)
{
ptr = fileopen(file2.txt) //open a second file, assign to same file pointer
fprint(ptr, some text) //print to file 2 not working here?
}
}
EDIT:
Not printing to second file...However...
I had to modify some open source code to use in a C project. Instead of building a library from the modified code, I'd like to just compile and build an executable from my own source combined with the modified open source code. The goal is to have a stand-alone package that can be distributed. I can get this to work just fine using th...
I am using C. I have a wchar_t pointer which pointing a a file path.
I was wondering, how I can check, whether it is ended with L".xls"?
Any function call I can use?
...
I am trying to set a global GetMessage hook on all threads. This is my DLL:
#include <windows.h>
__declspec(dllexport) LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBeep(0);
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
As you can see, it's not much. I just want it to call MessageBeep when...
I've always wondered the reasoning behind why we must always define D3DVERTEX. Is it because Microsoft wants to allow the opportunity to put this in a class and overload operators, or is there another reason?
Thanks
...
Sample code for fmod
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 0.14527, y = 3.14159;
printf("fmod(x, y) = %.6lf\n", fmod(x, y));
return 0;
}
$ gcc main.c -o main
I get
/tmp/ccztJO01.o: In function `main':
main.c:(.text+0x4d): undefined reference to `fmod'
collect2: ld returned 1 ...
I have an application loading a library containing a callback function for a global GetMessage hook. I get the procedure and pass it to SetWindowsHookEx to be set for all running threads.
The problem is that I want the DLL function to, under a certain circumstance like a keypress, tell the original application to exit, not all applicati...
I can never understand how to print unsigned long datatype in C.
Suppose boo is an unsigned long, then I try:
printf("%lu\n", unsigned_boo)
printf("%du\n", unsigned_boo)
printf("%ud\n", unsigned_boo)
printf("%ll\n", unsigned_boo)
printf("%ld\n", unsigned_boo)
printf("%dl\n", unsigned_boo)
And all of them print some kind of -12312312...
char * x="a";
how would i convert it to char y='a';
also if i have a short char * a="100"
how can i convert it to short b=100
thanks
...
In k&r we have managed to create an RPN.
The exercise now is to:
Add commands for handling variables, (It's easy to provide twenty-six variables with single letter names.) Add a variable for the most recently printed value.
So this is meant to act somewhat like the Python interpreter, where we can do:
>>>5
>>>_ (where _ prints 5)
>>>...
int size=2;
char *a0;
char **allargs;
short *a1;
void **args;
allargs=(char **)malloc(size*sizeof(char *));
allargs[0]="a";
allargs[1]="100";
args=(void **)malloc(size*sizeof(void *));
a0 = malloc(sizeof(char *));
*a0=(*allargs[0]);
args[0]=(void *)&a0;
fprintf(stderr,"assigned %c %c\n",*a0,*((char *)args[0]));
a1 = malloc(sizeof(short...