c

strings and pointers

Hello, I am new to C and reviewing some source code. But I am not sure what is happening with this code snippet. I really don't think it is doing anything, as in the debugging the output seems to be the same for tempstr. This is what I think, correct if I am wrong. *(tempstr + strlen(line)) is adding the length of line to tempstr and ...

When to use extern "C" in C++ ?

Possible Duplicate: Why do we need extern C{ #include <foo.h> } in C++? I have often seen programs coded like: extern "C" bool doSomeWork() { // return true; } Why do we use extern "C" block? Can we replace this with something in C++ ? Is there any advantage of using extern "C" ? I do see a link explaining this but why d...

Creating custom dictionaries in aspell with the C API

I am using aspell in my application for spell checking (a c/c++ app), and I want to use it to find best alternatives in a custom work list. I don't want to use a standard dictionary, as I only want to find words in my word list. I can find ways of adding words to a dictionary (aspell_speller_add_to_personal and aspell_speller_add_to_se...

splice from socket to pipe frozen

This code is based on splice-fromnet.c and splice-cp.c to splice from a socket to a pipe and from the pipe to a file but for some reason the first call to splice never returns. static size_t splice_from_net_to_file(int infd, int outfd) { int p[2]; size_t total = 0; if (pipe(p) == -1) return error("pipe"); while...

How to generate a compilation error when pointer types differ?

How do I write a macro CHECK(a, b) that generates compilation error when the two pointers a & b have different base type. CHECK((int*)0, (char*)0) -> compilation error CHECK((int*)0, (int*)0) -> works I'm looking for some C89 code, but C99 + gcc extensions will also do. ...

Char array in a struct - incompatible assignment?

Hi! I tried to find out what a struct really 'is' and hit a problem, so I have really 2 questions: 1) What is saved in 'sara'? Is it a pointer to the first element of the struct? 2) The more interesting question: Why doesn't it compile? GCC says "test.c:10: error: incompatible types in assignment" and I can't figure out why... (This ...

How does one configure Eclipse to compile using -std=c99?

The question is in the title. Using GCC version 3.4.5 on Windows Vista and a recent version of the Eclipse C/C++ IDE (not sure what version exactly because it's hard to figure out which version is the one for the whole IDE, but I downloaded it two weeks ago so it can't be that old). ...

How to cast a string to a function pointer in C?

Possible Duplicates: call a function named in a string variable in c Dynamically invoking any function by passing function name as string I have certain functions.. say, double fA1B1C1( .. ) { ... } double fA2B2C3( .. ) { ... } double (*fptr)( .. ); fptr myfunc; These functions are already defined. So...

Advanced IF statement in C

Hi, I've just reverse engineered a binary with IDA and loaded Hex Ray to check out a specific function. The generate C source code contains the following if statement: LP_ret_GlobalLock_1 = GlobalLock(hMem); LP_ret_GlobalLock_2 = LP_ret_GlobalLock_1; ... if ( !LP_ret_GlobalLock_1 || (v9 = *(_DWORD *)(v6 + 4), *(_DWORD *)v6 = LP_ret_Glo...

How to statically link to the CRT with GCC?

Using GCC4 in MAC OSX, Linux and Windows. Thanks. ...

Is there any way to change directory using C language?

Is there any way by which I can change to any directory by executing a C program? ...

Is there a library in plain C that converts GPX to KML, and other geo-formats?

Is there a library in plain C that converts GPX to KML, and other geo-formats? ...

Removing strings from C source code

Can anyone point me to a program that strips off strings from C source code? Example #include <stdio.h> static const char *place = "world"; char * multiline_str = "one \ two \ three\n"; int main(int argc, char *argv[]) { printf("Hello %s\n", place); printf("The previous line says \"Hello %s\"\n", place); return 0...

Gcov reporting unexpected cover results

I made some changes to a library to keep it inline with a project. I ran the test and everything still passed but the coverage is no longer 100%. I investigated and saw that the code is executed just not reported. But I have no idea why gcov is not reporting coverage for the line when it is executing. This is the code: int32_t Previous...

Does gcc automatically initialize static variables to zero?

I have a static variable declared but uninitialized in a function. Will this variable be initialized to zero automatically? static int idx; ...

Convert milliseconds to seconds in C.

Simple C question, how can I correctly and succintly convert milliseconds to seconds. There are two constraints: I've no floating point support in this tiny subset-of-C compiler I need the seconds rounded to the nearest second(1-499ms rounds down,500-999ms rounds up. Don't need to care about negative values) int mseconds = 1600; // sh...

simple string runtime error in C?

This code compiles fine but give segmentation fault error while running? Can anyone tell why? #include <stdio.h> #include <string.h> #include <math.h> int main() { const char s2[] = "asdfasdf"; char* s1; strcpy(s1, s2); printf("%s", s1); return 0; } ...

C++ IP Address human-readable form

In C/C++, you can use the regular gethostbyname() call to turn a dotted-IP address string ("127.0.0.1" in the case of localhost) into a structure suitable for standard socket calls. Now how do you translate it back? I know I can do some bit-shifting to get exactly which bit sets I want and just print those out, but is there any "standa...

How to create a statically linked extension for sqlite?

sqlite3_auto_extension looks like a good way to register a statically linked extension. But I don't understand the callback declaration: void (*xEntryPoint)(void); Shouldn't the callback be like sqlite3_extension_init? int sqlite3_extension_init( sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi ) ...

setting the maximum segment size in the tcp header

I am putting together a port scanner as a learning exercise. My problem is I'm trying to set the maximum segment size option(MSS) in the TCP header. I had a look at tcp.h, but I'm having trouble figuring out how to set it. I was hoping there would be an option like this: tcp_header->mss(32000); Something similar to the above was in tc...