Thread: chaining functions

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    54

    chaining functions

    this is some code I wrote .. I have a question about it because a while back someone on this forum mentioned that this is a form of daisy chaining functions and should be avoided.
    Code:
      for( y = 1; y < window->Nyscreen; y++ ){
        for( x = 1; x < window->Nxscreen; x++ ){
          real = (( x * image->ximage ) / window->Nxscreen
    	      - image->xoff);
          imaginary = image->yoff - (( y * image->yimage )
    				 / window->Nyscreen );
     
          putpixel(x, y, ( color( multiply(real,imaginary,max_escape ),max_escape)));
        }
    so I rewrote the code but Im not sure a: that I can avoid calling these functions in the for loop? and b: how would I do so? and c: should I try to?

    Code:
      for( x = 1; x < window->Nxscreen; x++ ){
        for( y = 1; y < window->Nyscreen; y++ ){
          real = (convx * x ) - window->xoff;
          imaginary = window->yoff - (convy * y);
          count = multiply(real, imaginary, me);
          colors = color(count,me);
          putpixel(x,y,colors);
    }
    this code is not in the main so I am calling 3 functions from a function .. is this ok?
    Im on a learning curve here so thanks for anyone looking at the thread in advance .. al.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's nothing wrong with having a function as an argument to another function. The only time it could possibly matter is if you are doing something like this:
    Code:
    char * foo( char *c );
    char * bar( char *c );
    void baz( char *a, char *b );
    ...
    char c = 'a';
    baz( foo( &c ), bar( &c ) );
    And the only reason that matters is you care about the order they are called.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mad_muppet View Post
    this is some code I wrote .. I have a question about it because a while back someone on this forum mentioned that this is a form of daisy chaining functions and should be avoided.
    Why? It's not a problem so long as you don't get lost in the shuffle.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. infinite loop with signal chaining
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 04-18-2008, 10:14 AM
  2. Hash Table with Chaining
    By osxd00d in forum C Programming
    Replies: 12
    Last Post: 12-04-2007, 09:01 PM
  3. Hash tables - chaining
    By cosmo1996 in forum C Programming
    Replies: 2
    Last Post: 08-14-2007, 11:53 PM
  4. Chaining Hash Tables (in C)
    By sql.scripter in forum C Programming
    Replies: 18
    Last Post: 09-25-2006, 01:05 AM
  5. Chaining two routers
    By golfinguy4 in forum Tech Board
    Replies: 0
    Last Post: 05-09-2005, 06:17 PM