Using sizeof() on a parameter array

Dale Worley worley at compass.com
Tue May 21 01:10:36 AEST 1991


In article <12151 at jarthur.Claremont.EDU> jseidman at jarthur.Claremont.EDU (Jim Seidman) writes:
   void test(char param[80]) {
       char local[80];

   }

Yes, the type of 'param' is 'char *'.  See section 3.7.1 of the ANSI
standard.  This makes is hard to pass arrays as arguments.  However,
if you wrap the array in a struct, the array will be passed as
requested!

    struct dummy {
	    char a[80];
    };

    void test(struct dummy param) {
	    printf("sizeof(param) = %d\n", sizeof(param));
    }

will print 80 as expected!

Dale

Dale Worley		Compass, Inc.			worley at compass.com
--
Q: Why does Internet raise issues of academic freedom and free
speech?
A:  Anything you can write publish, broadcast, or yell from the
top of a building, Internet can propagate further, faster, more
elegantly.  Thus, age-old issues of freedom of speech and
expression vs. public safety and moral sensibilities have moved
into this high tech arena.	-- Joe Abernathy
[And in an intensified form.]



More information about the Comp.lang.c mailing list