c

GTK Window configure events not propagating

I'm attempting to capture an event on a GTK window when the window is moved. I'm doing so with something that looks like this: void mycallback(GtkWindow* parentWindow, GdkEvent* event, gpointer data) { // do something... } ... GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_add_events(GTK_WIDGET(window), G...

FindWindow with partial window title (Windows, C)

Is there any API similar to FindWindow() but that searches the windows by partial title? The reason is that I need to the handle to a window that has a fix part on the title but the other part changes constantly. So for example the window title could be: DataBase read: XYDB or DataBase read: WZDB in the examples the fix part is "Dat...

Why is preprocessor usage less common in languages other than C/C++/ObjC ?

I've been a Java and VB.Net programmer for about 4 years and a C# programmer for about 6 months. I've also used a bunch of dynamic languages like Perl, Python, PHP, and JavaScript. I've never had a need for a preprocessor. My question is: why do you see such extensive use of preprocessors in C, C++, and Objective-C but rarely (or neve...

What should happen to the negation of a size_t (i.e. `-sizeof(struct foo)`))?

I'm dealing with some code at work that includes an expression of the form -(sizeof(struct foo)) i.e. the negation of a size_t, and I'm unclear on what the C and C++ standards require of compilers when they see this. Specifically, from looking around here and elsewhere, sizeof returns an unsigned integral value of type size_t. I can'...

Globbing in C++/C, on Windows

Is there a smooth way to glob in C or C++ in Windows? E.g., myprogram.exe *.txt sends my program an ARGV list that has...ARGV[1]=*.txt in it. I would like to be able to have a function (let's call it readglob) that takes a string and returns a vector of strings, each containing a filename. This way, if I have files a.txt b.txt c.txt i...

Passing a constant array to a function in C/C++

If I have a prototype that looks like this: function(float,float,float,float) I can pass values like this: function(1,2,3,4); So if my prototype is this: function(float*); Is there any way I can achieve something like this? function( {1,2,3,4} ); Just looking for a lazy way to do this without creating a temporary variable, bu...

why am i getting a SIGTRAP in gdb while debugging Ruby C extension?

I want to use rb_p() to aid in debugging a ruby C extension, but everytime i use it i get a SIGTRAP in gdb! here's an example: (gdb) p user_defaults $3 = 137559900 (gdb) call rb_p(user_defaults) {:fill=>true, :texture=>#} (gdb) n Program received signal SIGTRAP, Trace/breakpoint trap. is_a_hash (try_hash=137560420) at utils.c:65 (...

Is there a notification mechanism for when getifaddrs() results change?

Hi all, On startup, my program calls getifaddrs() to find out what network interfaces are available for link-local IPv6 multicasting. This works as far as it goes, but it doesn't handle the case where the set of available network interfaces changes after getifaddrs() has returned. Is there some way for the OS to notify my program when...

argh! what is wrong with this floodfill algorithm?!

I have been using a floodfill algorithm of the stack-based non-recursive variety and it seems to work perfectly except for one annoying situation: if use a line to cut an image in half and then floodfill one half, it floods the whole image! This only happens, however, when I do not put 'borders' around the image. If i draw a rectangle th...

Are snprintf and friends safe to use?

There was a question recently on SO (Why on earth would anyone use strncpy instead of strcpy?), which hade answers (answer 1, answer 2), that made me uncertain about other string functions with 'n' in their name, like snprintf (which I have been using extensively). Is snprintf safe to use? And generally, what are the safe functions from ...

Getting CPU usage stats from C on Solaris 10.

On Solaris 10, and in C, I'd like to regularly query numbers like The CPU usage for specific LWPs within that OS process. The memory usage for that OS process. I already know how to do the latter by opening /proc/pid/psinfo and reading from that (pr_rssize), but is there a way to implement the former? In the past I have forked off...

How do I loop through all files in a folder using C?

I want to remove a particular substring from all the file names in a directory. -- like 'XYZ.com' from 'Futurama s1e20 - [XYZ.com].avi' -- So basically i need to provide the method with a desired substring, and it has to loop through all file names and compare. I cant figure out how to loop through all files in a folder using C. (sor...

Delete last 10 characters from a text file

Hi, Is there any way to Delete last 10 characters from a text file ? Thanks ...

Using Doxygen with C, do you comment the function prototype or the definition? Or both?

I'm using Doxygen with some embedded C source. Given a .c/.h file pair, do you put Doxygen comments on the function prototype (.h file) or the function definition (.c file), or do you duplicate them in both places? I'm having a problem in which Doxygen is warning about missing comments when I document in one place but not the other; is ...

How to find (and replace) all old C-style data type casts in my C++ source code?

Hello How can I locate all old C-style cast in my source? I'm using Visual Studio, may be there is some compilator warning that I have to enable? Or use some software tool for this? ...

Does SPARC v9 have a double word compare and swap instruction?

So; on a 64 bit SPARC CPU which is v9 compliant, there exists I know a cas instruction. This operates on single word length values. I've also seen on the web reference to a casx instruction - but I can't find out anything much more about it. I'm wondering - is this a double word compare and swap? And if not, the general question is; ...

What's wrong with this C code?

I've tried reinventing the strcpy C function, but when I try to run it I get this error: Unhandled exception at 0x00411506 in brainf%ck.exe: 0xC0000005: Access violation writing location 0x00415760. The error occurs in the *dest = *src; line. Here's the code: char* strcpy(char* dest, const char* src) { char* dest2 = dest; whi...

How to decompose unix time in C

This seems like something no one should ever have to do, but I'm working on a kernel module for an embedded system (OpenWRT) in which it seems that time.h does include the timespec and time_t types, and the clock_gettime and gmtime functions, but does not include localtime, ctime, time, or, critically, the tm type. When I attempt to cas...

How to stringify an expression in C

Is there a way to evaluate an expression before stringification in c? example: #define stringify(x) #x ... const char * thestring = stringify( 10 * 50 ); The problem is that I want to get const char * thestring = "500"; And not: const char * thestring = "10 * 50"; Can this be done? ...

Differences between pointer initializations

I am speaking in Standard, K&R C. Given: const char a[] = {1, 2, 3}; const char *p = NULL; Are these two statements equivalent: *p = a; p = a; Each of them would be on the third line of the snippet. 1 and 2 certainly don't look the same. What's the difference between the two then? ...