In the code block below what's the impicit conversion that takes place in the if statement for 7? I would have though it would end up being (0x98 <= 0x07) but that's not what happens as the condition evaluates to true and DoMyStuff gets called.
char minstogo = 0x98;
if(minstogo <= 7) {
DoMyStuff();
}
...
I have been doing socket programming for many years, but I have never had a missed message using TCP - until now. I have a java server and a client in C - both on the localhost. They are sending short message back and forth as strings, with some delays in between. I have one particular case where a message never arrives on the client...
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
With the above macro, could someone please help me on understanding the "(s)-1" part, why's that?
and also macros like:
#define PAGE_ROUND_DOWN(x) (((ULONG_PTR)(x)) & (~(PAGE_SIZE-1)))
#define PAGE_ROUND_UP(x) ( (((ULONG_PTR)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)) )
I know the ...
My code looks like this:
char * decode_input(char ch)
{
switch(ch) {
case 'g':
return "get";
break;
case KEY_F(9):
return "quit";
break;
default:
return "unknown"...
I have been struggling for a few hours with all sorts of C tutorials and books related to pointers but what I really want to know is if it's possible to change a char pointer once it's been created.
This is what I have tried:
char *a = "This is a string";
char *b = "new string";
a[2] = b[1]; // Causes a segment fault
*b[2] = b[1]; //...
When using malloc and doing similar memory manipulation can I rely on sizeof( char ) being always 1?
For example I need to allocate memory for N elements of type char. Is multiplying by sizeof( char ) necessary:
char* buffer = malloc( N * sizeof( char ) );
or can I rely on sizeof( char ) always being 1 and just skip the multiplicatio...
Windows provides only GetTickCount up to Windows Vista and starting from that OS also GetTickCount64. How can I make a C program compile with calls to different functions?
How can I make a C compiler check whether a function is declared in the included header files and compile different portions of code depending on whether that particu...
Hello,
I have installed on my computer C++Test only with UnitTest license (only Unit Test license) as a Visual Studio 2005 plugin ( cpptest_7.2.11.35_win32_vs2005_plugin.exe ).
I have a sample similar to the following:
bool MyFunction(... parameters... )
{
bool bRet = true;
// do something
if( some_condition )
{
...
I am trying to include math.h in my Linux kernel module. If I use,
#include '/usr/include/math.h'
It give me theses errors:
error: features.h: No such file or directory
error: bits/huge_val.h: No such file or directory
error: bits/mathdef.h: No such file or directory
error: bits/mathcalls.h: No such file or directory
Why is this?
...
I need to specify the exact length of a string to be printed from a double value, but I don't want to restrict the output any more than is necessary.
What is the maximum length that a 6-digit precision double will have when formatted by printf()?
Specifically, what value should I give to X in printf("%X.6lg",doubleValue); to ensure tha...
Our SW Engineering department suggests we use the tool Imagix 4D to analyze our preemptive C code in order to detect data consistency risks. By data consistency risk we mean cases where one task/thread/ISR accesses data that another thread was in the process of accessing.
By looking at the website of the tool, it looks promising. Howeve...
Hi,
I am working on an application written in C. One part of the application should embed python and there is my current problem. I try to link my source to the Python library but it does not work.
As I use MinGW I have created the python26.a file from python26.lib with dlltool and put the *.a file in C:/Program Files (x86)/python/2.6/...
I'm the kind of dork who enjoys reading source code in his spare time. I'm also the kind of dork who has an iPhone. What is the best way to read and browse code on such a device?
My initial thought is to use something like LXR to generate hyperlinked pages, and upload them to my personal server, but I am interested in better/easier ways...
I'm enrolled in a masters computer science course. The course is using C and the instructor wants us to use Cygwin to compile programs if we are using windows.
I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compiler.
But I don't know where to go from here. I need to compile a single source file that...
Hi,
I'm working on a piece of scientific software that is very cpu-intensive (its proc bound), but it needs to write data to disk fairly often (i/o bound).
I'm adding parallelization to this (OpenMP) and I'm wondering what the best way to address the write-to-disk needs.
There's no reason the simulation should wait on the HDD (which is...
I'm reading data from a sqlite3 database using the C api. sqlite3_column_int64 returns a sqlite3_int64 object. How do I convert this to a long?
...
Hi
if I want to print by rows of
char boo[] =
"abcd"
"efgh"
"ijkl"
"mnop";
I'd go with
for(i = 0; i < 4; i++)
{
char row[] = "";
for(j = 0; j < 4; j+)
printf("%c", *(boo++))
putchar('\n');
puts(row);
}
my question is how I can print columns so I get
aeim
bfjn
cgko
dhlp
...
I want to get the size of a specific member in a struct.
sizeof(((SomeStruct *) 0)->some_member) works for me but I feel like there might be a nicer way to do it.
I could #define SIZEOF_ELEM(STRUCT, ELEM) sizeof(((STRUCT *) 0)->ELEM) and then use SIZEOF_ELEM(SomeStruct, some_member), but I wonder whether there is already something bett...
We need to tell the outcome of the following C program:
main()
{
int pid, k, som;
som = 0; k = 2;
pid = fork();
if(pid == 0)
k=5;
else
wait(0);
for(int i = 1; i <= k; i++)
som += i;
printf("%d", som);
}
My first expectation is 3. When a the fork call is made, the memory of the proces...
I have this global mouse hook setup in a DLL that watches for mouse gestures.
Everything works perfectly but with a hook set for WH_MOUSE_LL which is a low-level hook and one that doesn't need to be in an external injectable DLL.
Once I switch - to the more suitable one would say - WH_MOUSE mouse hook, everything falls apart. Once I cl...