0
void update(char array[10]) {
  // function implementation
}
int main(int argc, char **argv) {
  char array[10] = "welcome";
  update(array);
  return 0;
}

I am trying to pass a pointer-to-array to another function without losing its array metadata. In other words, when I am debugging and control jumps inside "update" function, I no longer can inspect the state of each of my 10 characters as they get modified by the "update" function because control is no longer within the scope where the array was created. Once control jumps out of the "update" function and returns to the "main" or calling function, only then I can see the updated version of the referenced array.

Is there a way to fix this?

As a side note, I am using the built-in debugger that comes with Visual Studio Code as well as the GCC compiler.

6
  • @Oka when the array of 10 characters is created within the scope of "main" function, I can expand all 10 characters using the debugger tool. However, once control jumps inside "update" function, I can only see the first character of the array. In other words, the array metadata is lost. Commented Nov 8, 2022 at 20:43
  • The metadata that you lose is the length of the array, since you transition from having a fixed length array to having a pointer to the beginning of a fixed, but unknown, length array. The way you do it might be different, but it should still be possible to view the contents. If you specify the debugger you are using, perhaps someone familiar with that specific debugger can help. And thumbs up for using a debugger! Commented Nov 8, 2022 at 20:46
  • @AviBerger I am using the built-in debugger that comes with Visual Studio Code. In addition, I am using the gcc compiler. Commented Nov 8, 2022 at 20:48
  • I've never used Visual Studio Code, but edit your post to add that information. Commented Nov 8, 2022 at 20:51
  • 1
    Try this perhaps. Commented Nov 8, 2022 at 20:58

0