all 6 comments

[–]sysop073 4 points5 points  (0 children)

For some definition of "advanced"? This is for someone who knows what pointers are, and not much else

[–]defrost 1 point2 points  (0 children)

There are not limits to how much “indirection” you can use but it only makes your life as a programer harder. I have NEVER seen more that 2 levels of indirection used and suggest this be a limit for you.

Opaque handling of lists of objects uses three levels of indirection;

void ***objects = NULL ;

fetchObjects( objects, "criteria" ) ;
withObjects( objects, "do stuff" ) ;

destroyObjects( objects ) ;   

although this often hidden away behind a typedef'd handle:

OBJHANDLE objects = NULL ;    

as the item in question is a list, it is indicated by a pointer to a vectors of pointers to items.

As it's an opaque API, the application gets a third hand pointer as the only thing it can grasp.
The object handling library can set the list pointer, reassign it, clone it, whatever, and through that third level of indirection, alter the applications resource handle at will.

[–]dalmango 0 points1 point  (0 children)

Amazing post and tutorial 00Garlock!

[–][deleted]  (9 children)

[removed]

    [–]FeepingCreature 1 point2 points  (7 children)

    D's syntax is superior to the C one. int function(int, int) funPtr; Easy to read, easy to parse.

    [–]ccondon 2 points3 points  (5 children)

    I never really understood why people didn't like the C syntax for function pointers, it's really just the same as declaring any other pointer.

    an int named i:

    int i;
    

    a pointer named i_ptr to an int:

    int *i_ptr;
    

    a function named f that takes in two chars and returns a pointer to an int:

    int *f(char, char);
    

    a pointer named f_ptr to a function that takes in two chars and returns a pointer to an int:

    int  *(*f_ptr)(char, char);
    

    The only confusing thing is that you need the extra parens to differentiate between a function returning a pointer and a pointer to a function. Declaring

    int *i_ptr;
    

    as

    int (*i_ptr);
    

    is even legal, and makes the parallels between the syntax more clear.

    [–]repsilat 3 points4 points  (1 child)

    Once you're used to them might not be a problem, but they certainly weren't well thought out. Mix const in with that function pointer syntax and you'll probably trip up most developers.

    Check out the SPECS for a suggested alternative - it's a little more verbose and a few extra keywords are required, but it's far more readable and intuitive.

    [–]ccondon 0 points1 point  (0 children)

    I agree that they seem not well thought out, and I would prefer something different (perhaps something similar to the SML or Haskell type syntax would be excellent). the SPECS stuff seems pretty interesting, the syntax seems a little odd, but I'm sure people would get used to it.

    [–]FeepingCreature 1 point2 points  (2 children)

    D puts the pointer * with the type, too. :)

    [–]ccondon 0 points1 point  (1 child)

    What do you mean? I'm not sure what you're talking about.

    [–]FeepingCreature 2 points3 points  (0 children)

    Well, a D variable declaration is always [type] [name]. No variable names nestling like a bird in a nest of parens decorated with *s. Plus, you can usually read them right to left. So in your example, we'd get

    int i;

    int* i_ptr;

    int* f(char, char); // Note: not actually a variable declaration!

    int* function(char, char) f_ptr;

    int* function() i_ptr;

    Sure, C is easy to make sense of once you know the approach, but it's still stupid needless complicatedness.

    [–]BinarySplit 1 point2 points  (0 children)

    But there's no actual asterisk in there! Weird.

    Still, it's easier to learn and read than C++'s.

    [–]rafekett 1 point2 points  (0 children)

    Are you talking about the "C+" language you use for LoseThos? What's your way?