Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does deleting the default value of function parameter still keep binary compatibility?

I'm now debugging code but need to keep binary compatibility. There now is a modification about the default value of function parameter.

void functionName(const type parameter = class::A::getValue());

Now I want to just change it like this :

void functionName(const type parameter);

Is it still binary compatibility?

like image 301
DONG Avatar asked Feb 26 '26 13:02

DONG


1 Answers

Default parameters don't change the type of a function. gcc 4.9.1 compiles this code without warnings:

#include <iostream>
using namespace std;

static void f (int x) {
  cout << x << endl ;
}
static void g() ;

int main() {
  f (99) ;
  g() ;
  return 0 ;
}

static void f (int x = 101) ;

static void g() {
  f() ;
}

Re-declaring f to take a default parameter value is allowed here, which means that its linkage is unchanged. So you'll be OK.

like image 69
TonyK Avatar answered Feb 28 '26 06:02

TonyK