小编Zac*_*ere的帖子

访问未声明的结构?

我有办法访问尚未声明的结构吗?

//Need to some how declare 'monitor' up here, with out moving 'monitor' above 'device'
//because both structs need to be able to access each others members

struct{
    int ID = 10;
    int Get__Monitor__ID(){
        return monitor.ID; //obvioulsly 'monitor' is not declared yet, therefore throws error and is not accessible
    }
} device;

struct{
    int ID = 6;
    int Get__Device__ID(){
        return device.ID; //because 'device' is declared above this struct, the ID member is accessible
    }
} monitor;
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
60
查看次数

获取浮点数的有符号位

我正在尝试找到一种方法来检查浮点数是否为负而不分支。

float a = -0.5;
int getSignOfa= *(int*)&a >> 31; //type-pun to int and get signed bit;
Run Code Online (Sandbox Code Playgroud)

这是检查浮点数有符号位的安全方法吗?

c

-3
推荐指数
1
解决办法
2431
查看次数

标签 统计

c ×1

c++ ×1