Hi, Johannes.
Using char curname[MAX_WINDOW_NAME_LENGTH] is easiest. This is called
stack allocation, and has the advantage that it is automatically cleaned up
when the scope exits.
A function pointer is just a variable to which you assign a pointer. Using
typedefs helps immensely to get it right. I think you're close, but I'd
need to check with a compiler to make sure I haven't myself made a syntax
error. Something like
typedef int (*compare_window_name_function)(char *name1, char *name2, int
length);
compare_window_name_function my_compare = strcmp;
if((*my_compare)(a_name, another_name, 10)) { printf("yeah!\n"); }
(I haven't compiled that, it's probably slightly wrong.)
Jeff Abrahamson
+33 6 24 40 01 57 <-- brièvement indisponible le 4 juillet
+44 7920 594 255 <-- will change 18 July
http://jeff.purple.com/
http://blog.purple.com/jeff/
On 19 June 2014 19:46, Johannes Altmanninger <[email protected]>
wrote:
>
> On 06/19/2014 08:27 PM, Jeff Abrahamson wrote:
>
> Thanks! This looks good, up to my late-afternoon ability to review code.
> I trust anyway that you'll eventually test it, too. ;-)
>
> Do you ever allocate or deallocate curname?
>
>
> Jeff Abrahamson
>
>
> I have never done all this...
> How should I allocate curname?
> Is it:
> char curname[MAX_WINDOW_NAME_LENGTH];
> Deallocating should just be `free(curname);`, right?
>
> Also I am a stuck at the function pointer.
> From what I understood it is a function, that takes the name and match_type
> and returns a comparison function
> Is this the right type?
> int (*compare_window_names)(char* name, int match_type)
>
_______________________________________________
Ratpoison-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/ratpoison-devel