To add to ouah's answer I re-worked the code to allow compilation with just the -std=c11 flag:
#include <stdio.h>
#include <math.h>
typedef struct Price2 {
double close;
double high;
double low;
} Price2;
typedef struct {
union {
struct { // Price2 equivalent textually re-defined within OLHC2
double close;
double high;
double low;
};
Price2 p;
};
double open;
} OHLC2;
double range2(Price2 p){ //behaviour defined for struct Price2
return(p.high - p.low);
}
double travelRange2(OHLC2 p){ //behaviour for struct Price2 re-used by OHLC2
return (fabs(p.open - p.low) + range2(p.p) + fabs(p.high - p.close));
}
int main(){
OHLC2 msft2={.close=33.4,
.open=32.1,
.high=35.5,
.low=30.23};
printf("Today's travel Range for MSFT was %f\n",travelRange2(msft2));
}
The key unsatisfyingly is to replace the reference to the base structure in the derived structure by cutting and pasting the base struct definition sans tag and everything works. This seems to obviate some of the benefits of code re-use that works much better with the Microsoft extension switch.