In the following sample code, why sample_breaks fails to compile?

#define ONE_FRAME_OF_30FPS_2 = 1.0/30.0;

void sample_works() {
    double partOfSecondAVFoundationNumber = 2 * 1.0/30.0;
}

void sample_breaks() {
    double partOfSecondAVFoundationNumber = 2 * ONE_FRAME_OF_30FPS_2;
}
有帮助吗?

解决方案

It becomes this:

void sample_breaks() {
    double partOfSecondAVFoundationNumber = 2 * = 1.0/30.0;;
}

after preprocessing. So you would expect an error.

Change to

#define ONE_FRAME_OF_30FPS_2 (1.0/30.0)

instead.

其他提示

#define ONE_FRAME_OF_30FPS_2 = 1.0/30.0;

Should be,

#define ONE_FRAME_OF_30FPS_2 1.0/30.0

Remember, after preprocessing, ONE_FRAME_OF_30FPS_2 will be replaced by 1.0/30.0. You are not assigning ONE_FRAME_OF_30FPS_2.

Its because your macro is wrong. It should be:

#define ONE_FRAME_OF_30FPS_2 1.0/30.0
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top