我有兴趣学习更多x86/x86_64程序集.唉,我在Mac上.没问题,对吧?
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build
5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
我在C中写了一个简单的"Hello World",以获得我将要编写的代码类型的基线.我在大学时做了一点x86,并且查了很多教程,但是没有一个看起来像我在这里看到的怪异输出:
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
Leh_func_begin1:
pushq %rbp
Ltmp0:
movq %rsp, %rbp
Ltmp1:
subq $32, %rsp
Ltmp2:
movl %edi, %eax
movl %eax, -4(%rbp)
movq %rsi, -16(%rbp)
leaq L_.str(%rip), …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我希望能够维护一个可能都指向nil的指针数组.
Equipment *equipment[19];
Run Code Online (Sandbox Code Playgroud)
但是,我发现我不能将指针数组或双指针设置为对象的属性.
当我不能使用C风格的数组时,我的解决方法是使用NSArray对象.所以我尝试做类似以下的事情:
NSMutableArray *equipment = [NSMutableArray arrayWithCapacity: NUM_EQUIPSLOTS];
for (int i=0; i<NUM_EQUIPSLOTS; i++) {
[equipment setObject: nil atIndexedSubscript: i];
}
Run Code Online (Sandbox Code Playgroud)
这里的想法是我有一个空指针数组,稍后会指向东西.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x246e012 0x1e4be7e 0x2421b6a 0x2421a20 0xebd02 0xde82b 0xc9d5a 0xcb6bd 0x4d525 0xc94fa 0xc8b6a 0xa18157 0xa18747 0xa1994b 0xa2acb5 0xa2bbeb 0xa1d698 0x3176df9 0x3176ad0 0x23e3bf5 0x23e3962 0x2414bb6 0x2413f44 0x2413e1b 0xa1917a 0xa1affc 0xc8526 0x1fa5)
libc++abi.dylib: terminate called throwing an exception
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用C风格的数组和单个对象轻松地完成这项工作.我宁愿这样做而不是像哑巴一样: …
我正在关注这个人关于 C++ Lambdas 的博客文章http://cpptruths.blogspot.com/2014/03/fun-with-lambdas-c14-style-part-1.html,在编译他的代码时,我遇到了编译器错误:
variable 'unit' cannot be implicitly captured in a lambda with no capture-default specified"
Run Code Online (Sandbox Code Playgroud)
它引用的行如下:
auto unit = [](auto x) {
return [=](){ return x; };
};
auto stringify = [](auto x) {
stringstream ss;
ss << x;
return unit(ss.str());
};
Run Code Online (Sandbox Code Playgroud)
这家伙似乎了解 C++ 中的新 Lambda 功能,而我当然不知道,这就是我现在在这里的原因。有人可以阐明这个问题吗?我需要做什么才能正确编译此代码?
提前致谢!:)
编辑:事实证明问题不在于单位或字符串化。让我粘贴新代码:
auto unit = [](auto x) {
return [=](){ return x; };
};
auto stringify = [unit](auto x) {
stringstream ss;
ss << x;
return unit(ss.str());
};
auto …Run Code Online (Sandbox Code Playgroud) 可以说我有一个简单的类,如下所示:
@interface A {
// @public
int var;
}
// @property(some_property) int var;
@end
Run Code Online (Sandbox Code Playgroud)
当我想访问变量var时,我有一些选择.如果我公开var,我可以这样做:
A objectA = [ [ A alloc ] init ];
NSLog( @"%d", objectA->var );
objectA->var = someNumber;
Run Code Online (Sandbox Code Playgroud)
如果我把它变成一个属性,我将不得不做更像这样的事情:
A objectA = [ [ A alloc ] init ];
NSLog( @"%d", objectA.var ); // dot-syntax
NSLog( @"%d", [ objectA var ] ); // get-syntax
[ objectA setVar: someNumber ];
Run Code Online (Sandbox Code Playgroud)
我已经尝试了两种并且它们工作正常但我的问题是使用旧式指针表示法来访问对象内部的变量有多危险?以后我是否需要担心我现在应该通过标准化我的方法访问来解决这个问题?或者我可以逃脱这样做但是我想要它只要有效吗?