c

When is it worth using a pointer to struct in a struct definition?

Sorry if the question isn't clear; I found it pretty hard to explain in one sentence. Say I have a struct with a member which is a struct, e.g. the following: struct A { struct B b; }; Lets say I intend instances of this structure to be heap-allocated always. Is there anything to be gained by changing it to this? (i.e. keeping a ...

Parsing a web page without broken strings.

I'm trying to parse some strings from a web page but I keep getting strings that happen to be broken up with no way to check if the string is complete or not. At the moment, I have a buffer of 1024 bytes that I'm receiving parts of the page with. What should I do to make sure I get the full string, preferably without an overly large buff...

C/C++ Registry Help

I am programming an mp3 application, and I have it so it starts on start up. However when looking at it in msconfig it says manufacturer is unknown. How can I make it say "daxsoft"? Is there a a way to do this without a .rc file? ...

Trying to embed python into tinycc, says python symbols are undefined

I've literally spent the past half hour searching for the solution to this, and everything involves GCC. What I do here works absolutely fine with GCC, however I'm using TinyCC, and this is where I'm getting confused. First the code: #include <Python.h> #include <stdio.h> int main(int argc, char*argv[]) { Py_Initialize(); PyRun_...

Is Perl or C faster at parsing?

I have a few very large log files, and I need to parse them. Ease of implementation obviously points me to Perl and regex combo (in which I am a still novice). But what about speed? Will it be faster to implement it in C? Each log file is in the order of 2 GB. ...

How to allow more memory and avoid stack overflow on lots of recursion?

I'm testing the timing of an algorithm that does lots of recursive calls. My program dies at about 128k recursive calls, and this takes only .05 seconds. I'd like to allow more memory to have longer timings in my analysis. I'm running linux and using gcc. Is there a system call, or environment variable, or gcc flag, or wrapper, or someth...

How to implement ping request in C langauage for Windows platform?

I want to implement ping request in C language.I am working on Windows platform.Can any one suggest how to implement it or if code is already available then from where i can find it? ...

Are inline functions in C/C++ a way to make them thread-safe?

I make the following reasoning, please tell me what's wrong (or right) about it: "If inlining a function duplicates the code in the place the function is called, then the static and local variables are duplicated for each function calling it and if there is only one thread running the function that calls the inlined one at the same time...

Short circuit error handling in C

I was wondering if there was a better way of handling the case in C where you want to exit a function as soon as you encounter an error in a series of expressions. (in this case, its a function that returns a NULL on error) e.g. in some C code where they tried to short circuit error handling by combining a series of statements with AND...

A minimal hash function for C?

I can't use boost:hash because I have to stick with C and can't use C++. But, I need to hash a large number (10K to 100k) of tokens strings (5 to 40 bytes length) so that search within those are fastest. MD5, SHA1 or any long hash function seems too heavy for a simple task, I am not doing cryptography. Plus there is the storage and com...

Memory usage of a child process?

I'm running a sort of "sandbox" in C on Ubuntu: it takes a program, and runs it safely under the user nobody (and intercepts signals, etc). Also, it assigns memory and time limits, and measures time and memory usage. (In case you're curious, it's for a sort of "online judge" to mark programs on test data) Currently I've adapted the safe...

GCC Inline Assembly: Jump to label outside block

When using inline assembly under MSVC, one is allowed to jump outside of the assembly block by referencing a label in the C/C++ code, as explained in this MSDN article. Can such thing be done when using inline assembly under GCC? Here's an example of what I'm trying to accomplish: __asm__ __volatile__ ( " /* assembly code */ " " j...

Why can I not assign interchangeably with two structs that have identical contents?

I'm trying to learn C and I've come across something weird: struct { int i; double j; } x, y; struct { int i; double j; } z; Here, you can see I created two structs that are identical in their elements. Why is it that when I try to assign x = z it will generate a compile error but x = y does not? They have the same contents...

C array declaration and assignment?

I've asked a similar question on structs here but I'm trying to figure out how C handles things like assigning variables and why it isn't allowed to assign them to eachother if they are functionally the same. Lets say I have two arrays: int x[10]; int y[10]; Why won't x = y compile? If they are both the same "signature" like that,...

How to compare ends of strings in C?

I want to make sure my string ends with ".foo". I am using C, a language I am not totally familiar with. The best way I have found to do it is below. Any C gurus want to make sure I'm doing this elegantly and wisely? int EndsWithFoo(char *str) { if(strlen(str) >= strlen(".foo")) { if(!strcmp(str + strlen(str) - strlen...

Windows pointer bitmap not being correctly updated

So, I'm writing a text editor, using MDI. I have a frame window, child windows and each child window has a text-area window. Now, my problem is the pointer. It's not setting itself to the correct bitmap. So for example, if I move the pointer to the border, it correctly turns into the left-right drag icon. That's all good and well - ...

What is the maximum size of buffers memcpy/memset etc. can handle?

What is the maximum size of buffers memcpy and other functions can handle? Is this implementation dependent? Is this restricted by the size(size_t) passed in as an argument? ...

How to get rid of gcc assembler warning "setting incorrect section attributes for .init" in C code?

I have the following C code: struct myStruct_t { const char m_name[60]; const uint32_t m_data; }; const struct myStruct_t myStruct __attribute__(( __aligned__( 64 ), section(".init") )) = { "myName", (uint32_t)&someOtherStruct }; When I compile in gcc 4.1.1 (for PS3), I get the warning: 1>c:/t...

Small open source Unicode library for C/C++

Does anyone know of a great small open source Unicode handling library for C or C++? I've looked at ICU, but it seems way too big. I need the library to support: all the normal encodings normalization finding character types - finding if a character should be allowed in identifiers and comments validation - recognizing nonsense ...

How do I mark code with side effects?

I'm working on a project on an 8051 where every byte counts. As such, I am using some global variables where I normally wouldn't. The normal method of passing pointers into a function adds too much overhead here. I have a number of functions that use single bit variables (a compiler specific extension to C) to signal the outcome of a ...