小编Wil*_*haw的帖子

摆脱 IAR 编译警告 Pa039 吗?“使用未对齐结构成员的地址”

ARM 的 IAR 编译器...

我有一个使用包装的结构

 #pragma pack(push, 4)
 typedef struct {
    int a;
    double b;
 } my_t;
 #pragma pack(pop)
Run Code Online (Sandbox Code Playgroud)

我想获取一个字段的地址,然后转换为char *.

my_t d;
char * p = (char *)(&(d.b));
Run Code Online (Sandbox Code Playgroud)

我可以在不使用编译指示禁用警告的情况下实现无警告吗?

c pointers compiler-errors iar

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

如何在 macOS 上以编程方式在 Swift 中添加 NSView

试图以编程方式添加一个简单的 NSView。

它不会出现。

** 答案 **:在 .backgroundColor = .black 之前做 .wantsLayer = true

我将颜色设置为黑色,所以我希望窗口中有一个黑色方块。

我正在使用 Xcode 10.2 Swift 5

import Cocoa

class ViewController: NSViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let newView = NSView(frame: NSRect(x: 10,y: 10, width: 100,height: 100))
        newView.layer?.backgroundColor = .black
        newView.wantsLayer = true
        self.view.addSubview(newView)
    }
}
Run Code Online (Sandbox Code Playgroud)

macos xcode cocoa swift

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

标签 统计

c ×1

cocoa ×1

compiler-errors ×1

iar ×1

macos ×1

pointers ×1

swift ×1

xcode ×1