I was playing around with a simple program (see below) and I came across behavior that did not seem correct. I ran the program with gdb as shown below, and it does not seem to read the passed arguments to func correctly, for instance it says b=21845, and even says . Is there an explanation for this?
I am running this on a MacBook Pro, 2.3 GHz 8-Core Intel Core i9, MACOS 13.1 (22C65). I compiled the program with: g++ -std=c++2a test.cpp -g -lpthread -lstdc++fs -o test I got the DBG debugger from https://marketplace.visualstudio.com/items?itemName=coolchyni.beyond-debug. It is GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1, configured as x86_64-linux-gnu. I am using visual studio code.
Code: test.cpp
#include <iostream>
void func(int b, int &c)
{
  std::cout << b <<" and " << c<< std::endl;
  
}
int main()
{
  
  int num2 = 4;
  int &num3 = num2;
  func(num2, num3);
  
  return 0;
}
GDB Run
Starting program: /home/es927/exper/test 
Breakpoint 1, main () at test.cpp:10
10        int num2 = 4;
(gdb) s
11        int &num3 = num2;
(gdb) s
12        func(num2, num3);
(gdb) s
func (b=21845, c=<error reading variable>) at test.cpp:4
4       {
(gdb) s
5         std::cout << b << " and " << c << std::endl;
(gdb) s
4 and 4
6       }
(gdb) s
main () at test.cpp:14
14        return 0;
(gdb) s
15      }
(gdb) c
Continuing.
[Inferior 1 (process 1235898) exited normally]
I was expecting the values of the passed arguments when stepping after code line 12.
 
    