Pelles C forum

C language => Expert questions => Topic started by: andi.martin on December 27, 2008, 11:02:16 PM

Title: sizeof operator on parametric arrays
Post by: andi.martin on December 27, 2008, 11:02:16 PM
Hi all,

is it correct, that an array as functional parameter degrades to a pointer?

Example:
#include <stdio.h>

typedef char test_t[200];

void func(test_t t)
{
  printf("%d", sizeof(t)); // returns 4 instead of 200
}

int main(int argc, char *argv[])
{
  test_t t;
  func(t);

  return 0;
}


Regards,
Andreas
Title: Re: sizeof operator on parametric arrays
Post by: severach on December 28, 2008, 08:43:50 AM
A quick look at the assembly code in the debugger shows the answer. The code is identical whether or not you use & on the structure.
Title: Re: sizeof operator on parametric arrays
Post by: JohnF on December 28, 2008, 08:46:03 AM
Yes, the array will degrade to a pointer so the sizeof operator will give the size of a pointer. If you need the size of the array you have to pass that as well.

John