c

help with implementation of strspn( )

The definition of library function strspn is: size_t strspn(const char *str, const char *chars) /*Return number of leading characters at the beginning of the string str which are all members of string chars.*/ e.g. if ‘str’ is “fecxdy” and ‘chars’ is “abcdef” then the function would return 3, since ‘f’, ’e’ and ‘c’ all appear somewhe...

what is wrong with this code snippet

Folks, here is an implementation of memset(), however I have been told that there is one logical mistake in the code. Could you help me find it. I feel that a double pointer for the target string should be passed to this function, which will be like passing the address of the pointer variable and not the pointer itself. I am getting a...

Why isn't all code compiled position independent?

When compiling shared libraries in gcc the -fPIC option compiles the code as position independent. Is there any reason (performance or otherwise) why you would not compile all code position independent? ...

Difference between binary search tree and m-way tree

Please explain the difference between a binary search tree and m-way tree? ...

How do I refer to a global variable in a dynamically linked library?

The environment is Solaris on 32bit SPARC, but I think this is a more general issue with dynamic linking and/or position independent code. I have an assembly program that I compile as position independent code and dynamically link to it from a C program. It works fine, except that I can't refer to any memory reserved by the assembly pro...

getch is deprecated

Hi there, Somewhere back in time i did some C and C++ in college, but I didn't get to many attention to C++. Now I wish to pay some attention to C++ but when I'm using getch() function, i get the warning from below. Warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. Se...

A way to convert byte stream to packet stream in C89 on an embedded device.

I’m working on with an embedded device that is connected to PC using rs232 (rs232 over USB). I’m thinking about developing my own protocol: <MAGIC><LENGTH><BINARY DATA><CRC> but I don’t want to reinvent the wheel. Please note that: I'm thinking about quite restricted device: 4kb of RAM, no kernel, nor standard C lib. Can you think...

C/C++ Machine Learning Libraries for Clustering

What are some C/c++ Machine learning libraries that supports clustering of multi dimensional data? (for example K-Means) So far I have come across SGI MLC++ http://www.sgi.com/tech/mlc/ OpenCV MLL I am tempted to roll-my-own, but I am sure pre-existing ones are far better performance optimized with more eyes on code. ...

is it possible to use regex in c++?

Duplicate of: There is a function to use pattern matching (using regular expressions) in C++? I'm not sure where one would use it... are there any parser-type functions that take some regex as an argument or something? I just found out that my editor will highlight a line after / as "regex" for C/C++ syntax which I thought was weird... ...

How to free dynamic allocated variable by SIGTERM?

Hi, I work on code something like this ... HEADERS ... int *var; void child() { ... //some work free(var); exit(EXIT_SUCCESSFUL); } int main(void) { ... //allocate variable var = (int *) malloc(N*sizeof(int)); ... //work with var for(int i; i<PROC_COUNT; i++) { pid_t child = fork(); if(pid == 0) { child...

llvm vs c-- ; how can llvm fundamentally not be better for haskell than c-- ?

I've been excited about llvm being low enough to model any system, and saw it as promising that Apple was adopting it; but then again Apple doesn't specifically support Haskell; and, some think that Haskell would be better off with c-- : That LLVM'ers haven't solved the problem of zero-overhead garbage collection isn't too surpris...

C/D line drawing package

I find my self in need of a line drawing package. I need to pop a window and draw lines and points. Text would be nice but I can live without it. Most importantly, I need something that is dirt simple to get running. I don't have time to dink around with libs (if I did have time I'd be willing but I'm already way behind as it is). I'd p...

How can I typedef a function pointer that takes a function of its own type as an argument?

Example: A function that takes a function (that takes a function (that ...) and an int) and an int. typedef void(*Func)(void (*)(void (*)(...), int), int); It explodes recursively where (...). Is there a fundamental reason this can't be done or is there another syntax? It seems to me it should be possible without a cast. I'm really tr...

Find header file that defines a C function

Shouldn't be hard, right? Right? I am currently trawling the OpenAFS codebase to find the header definition of pioctl. I've thrown everything I've got at it: checked ctags, grepped the source code for pioctl, etc. The closest I've got to a lead is the fact that there's a file pioctl_nt.h that contains the definition, except it's not act...

Cost/benefit of multi-threaded text processing

I am working on a real-time syntax highlighter for the iPhone and I have created a custom UIView that takes a string, parses it and then highlights it in its drawRect: method. I've also implemented a blinking cursor. However, it is starting to get a little slow and I think that when I implement multi-line processing and chunk-processing,...

Concurrently read from a single file

I have the following problem situation. A bunch of data is split across 10k small files (approx. 8-16 kib each). Depending on user input, I have to load these as fast as possible, and process them. More precisely, each data packet can be split into 100-100k files, and there are approximately 1k data packets. Most of them are the smaller ...

C calendar structure

Hi, could someone take a quick look at this C code and see why I get the compiler error? It is a function for entering details into a calendar structure, and should create one node, i.e. one 'event' on the calendar. struct event enter_key(void) { int day,month,year,starttime,endtime,length; char* descp; struct event*...

Compile Build and c file on Windows

I have a directory that has the following files Build asc2uni.c asc2uni.1 I have to compile it, but the problem is I don't know how what is the compiler to use for this format and how to do it. Any ideas? Edit: I am trying to compile this on Windows XP. Edit 2: The Build file content: cc -I../Modules -O -o asc2uni asc2uni.c ../M...

Power On Self Test

Hi, Any good place to learn about POST and how to design and code one? I am a C++ programmer and quite baffeled with the term. Thanks ...

Does Duff's Device work in other languages?

Many years ago while working on a tight graphics I/O problem, Tom Duff unrolled a loop and created his Duff's Device as follows: dsend(to, from, count) char *to, *from; int count; { int n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; ca...