NO

Author Topic: sizeof operator on parametric arrays  (Read 3710 times)

andi.martin

  • Guest
sizeof operator on parametric arrays
« 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

severach

  • Guest
Re: sizeof operator on parametric arrays
« Reply #1 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.

JohnF

  • Guest
Re: sizeof operator on parametric arrays
« Reply #2 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