FidoNet Echomail Archive
c_echo

<<< Previous Index Next >>>

From: Robert Lewis
To: All
Date: 2004-12-20 10:43:28
Subject: [C] RE: C Digest, Vol 15, Issue 2

From: Robert Lewis <robert.lewis{at}shaw.ca>

I wonder if someone could show me how to fill a structure (preferably,
second choice is an array) with pointers to functions and then the
structure of functions, that is execute each of the functions pointed in
the structure.

I just can't figure out the pointer syntax or how to pass control to the
same. Or is this even possible?

Thanks

Bob Lewis

-----Original Message-----
From: c-bounces{at}snippets.org [mailto:c-bounces{at}snippets.org] On Behalf Of
c-request{at}snippets.org
Sent: Monday, December 20, 2004 10:00 AM To: c{at}snippets.org
Subject: C Digest, Vol 15, Issue 2

Send C mailing list submissions to
        c{at}snippets.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.snippets.org/mailman/listinfo/c
or, via email, send a message with subject or body 'help' to
        c-request{at}snippets.org

You can reach the person managing the list at
        c-owner{at}snippets.org

When replying, please edit your Subject line so it is more specific than
"Re: Contents of C digest..."


Today's Topics:

   1. re: My brain has gone south (Bruce)
   2. Re: re: My brain has gone south (Len Philpot)


----------------------------------------------------------------------

Message: 1
Date: Mon, 3 Jan 2005 00:30:05 -0600
From: "Bruce" <snaphook{at}swbell.net>
Subject: [C] re: My brain has gone south
To: <c{at}snippets.org>
Message-ID: <000401c4f15d$aa2d8920$1c02a8c0{at}bruce>
Content-Type: text/plain;       charset="iso-8859-1"

You can't get the size of an array after you pass it to a function because
you can't pass an array to a function directly.  It is converted to a
pointer, which explains the sizes you're getting.  If you really wish to do
this, wrap the array in a structure and pass that, then you can get the
size by doing:

#include <stdio.h>

typedef struct
{
   int array[256];

} PASS_ARRAY;

void myfunc( PASS_ARRAY *ar);

double rnd(double x)
{
    return floor(x + 0.5);
}

int main()
{
        myfunc( &p);
        return 0;
}

Other more typical solutions, since you usually don't want to pass a large
amount of data on the stack like this code does:

1.  Terminate the array with a special char and loop till you find it 2. 
Declare the size with a #define constant with global scope 3.  Pass the
size as an arg to the function

void myfunc( PASS_ARRAY *ar)
{
   int arraysize = sizeof(ar->array) / sizeof(ar->array[0]);
   printf("Array is %d bytes", arraysize);
}




------------------------------

Message: 2
Date: Sun, 19 Dec 2004 14:47:47 -0600
From: "Len Philpot" <len{at}philpot.org>
Subject: Re: [C] re: My brain has gone south
To: SNIPPETS C programming conference <c{at}snippets.org>
Message-ID: <41C59493.11753.65F3E53{at}localhost>
Content-Type: text/plain; charset=US-ASCII

> You can't get the size of an array after you pass it to a function
> because you can't pass an array to a function directly.  It is
> converted to a pointer, which explains the sizes you're getting.  If
> you really wish to do this, wrap the array in a structure and pass
> that, then you can get the size by doing:

I'll take it as a small personal victory that I actually thought of that at
some point. Maybe there's hope for me yet! :-)


> 2.  Declare the size with a #define constant with global scope 3.
> Pass the size as an arg to the function

In this case, #2 would work just fine, since I'm passing MAX_PATH + 1 and I
can't imagine why I'd want less room, but making it was more flexible was
starting to pique my interest and I ended up doing #3.

Thanks.

--
 Len Philpot                          ><>
 len{at}philpot.org       http://philpot.org/






------------------------------

_______________________________________________
C mailing list
C{at}snippets.org
http://www.snippets.org/mailman/listinfo/c
Gateway to the FidoNet C_Echo


End of C Digest, Vol 15, Issue 2
********************************

--- BBBS/LiI v4.01 Flag-5
 * Origin: Prism's_Point (1:261/38.1)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267


<<< Previous Index Next >>>