This questions is relevant to an application I'm currently working on, but I don't have much to go on in terms of finding an answer. The basic questions is what is the delay (or how to estimate it) between the time that a user presses one of the mouse buttons until the information is posted to the window message queue and is available fo...
Hi folks!
What's the best way to convert an "uint8_t" to an "sint8_t" in portable C.
That's the code I came up with ....
#include <stdint.h>
sint8_t DESER_SINT8(uint8_t x)
(
return
(sint8_t)((x >= (1u << 8u))
? -(UINT8_MAX - x)
: x);
)
Is there a better/simpler way to do it? Maybe a way without ...
Is the above output in the format that should be expected from xxd or does the presence of the bizzare characters on the right suggest i've done something wrong?
I'm attempting to serialise a simple linked list and that's the output i get. Would failing to remove the sentinal character "\0" from the serialisation cause the error?
...
I am using CuTest for unit testing and would like to get information about code coverage. Are there any code coverage tools available for C?
Thanks
...
This would be easy with fork(), but I've got no MMU. I've heard that vfork() blocks the parent process until the child exits or executes exec(). How would I accomplish something like this?:
pid_t pid = vfork();
if (pid == -1) {
// fail
exit(-1);
}
if (pid == 0) {
// child
while(1) {
// Do my daemon stuff
}
...
By huge numbers, I mean if you took a gigabyte (instead of 4/8 bytes etc.) and tried to add/subtract/multiply/divide it by some other arbitrarily large (or small) number.
Adding and subtracting are rather easy (one k/m/byte at a time):
out_byteN = a_byteN + b_byteN + overflowBit
For every byte, thus I can add/subtract as I read the ...
Hello,
How to write code which specifies timeout to BSD sockets connect syscall ? I writing iPhone application and i need to wait long time to get response from connect syscall. Any Examples ?
Thanks
Now i have something like this:
host_name = NULL ;
host_name = gethostbyname([[host_value hostname] UTF8String]) ;
if (host_name != NU...
As the title says, I always wonder why scanf must take the address of operator (&).
...
I'm compiling some C code, and I get the error
typedef 'A' is initialized (use decltype instead)
On one of my struct declarations. What could be causing this?
...
The people who really know the answer to this question are those who develop for programs or libraries which are included in Linux distributions, and which depend on other libraries which are included in Linux distributions. Them just telling me what they do in terms of the development environment I'm describing would be helpful.
The p...
a=[1,3,6,7,1,2]
Which is the best sorting technique to sort the following array and if there are duplicates how to handle them.
Also which is the best sorting technique of all....
void BubbleSort(int a[], int array_size)
{
int i, j, temp;
for (i = 0; i < (array_size - 1); ++i)
{
for (j = 0; j < array_size - 1 - i; ++...
My rectangle structure has these members:
x, y, width, height.
Given a point x, y
what would be the fastest way of knowing if x, y is inside of the rectangle? I will be doing lots of these so speed is important.
...
Possible Duplicate:
What is the difference between char s[] and char *s in C?
I was wondering what is the difference between
char *p1 = "some string";
and
char p2[] = "some string";
in terms of memory, can these not be treated in the same way?
e.g.
void foo(char *p);
...
foo(p1);
foo(p2);
...
On my Solaris 10 update 9 system the following command yields:
#isainfo -b
64
But if I create the following program in C with limits.h is included I get:
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("Maximum integer value on this system is = %d\n", INT_MAX);
}
gcc on64.c -o on64
./on64
Maximum integer va...
Consider the following piece of C code:
#include <stdint.h>
uint32_t inc(uint16_t x) {
return x+1;
}
When compiled with gcc-4.4.3 with flags -std=c99 -march=core2 -msse4.1 -O2 -pipe -Wall on a pure x86_64 system, it produces
movzwl %di,%eax
inc %eax
retq
Now, unsigned overflow is predicted in C. I do not know much about x86_64...
PHP's C source can be found at http://svn.php.net/viewvc/php/php-src/trunk/. If I want to find the implementation of a specific PHP function, how to quick locate it in that SVN source?
...
I want the output of the shell command (echo free | grep Mem| awk '{print $2}') collected in a variable so that I can use it in a C program. So I have the code here.
system("TOTAL=$(echo `free | grep Mem| awk '{print $2}'`)");
popen("grep -v procs $1 | grep -v free | awk '{USED=TOTAL-$4-$5-$6;print USED}'", "r");
Can I use the varia...
Hey guys I'm trying to write a program that takes in a plaintext file as it's argument and parses through it, adding all the numbers together and then print out the sum. The following is my code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
static int sumNumbers(char filename[])
{
int sum = 0;
FILE *file = fopen(fi...
const int z = 420;
printf("\n%d | %d",z ,*(&(*(&z+1))-1) );
// O/P:420 | 420
printf("\n%u | %u",&z,(&(*(&z+1))-1) ); //address
// O/P:1310548 | 1310548
*((char *)&z+1) = 21; //I change value for the 1st-Bit
//corrupting constant
printf("\n%d | %d",z ,*(&(*(&z+1))-1) );
//the com...
I have a C application (not using C99 features) that does some heavy string processing. Since the string lengths are not known, statically allocated buffers is not an option for me. I have created a simple string implementation which will abstract the null termination and dynamic expansion of buffers.
Here is how it looks like,
struct ...