2013-11-27 35 views
0

快速提问:如何在Objective-C中使用const float *类型的常量调试值?通过调试你的意思是NSLog“const float *”

%@ , Format specifies type 'id' but the argument has type 'const float *' 
%d , Format specifies type 'int' but the argument has type 'const float *' 
%f , Format specifies type 'double' but the argument has type 'const float *' 
+0

您的警告是什么? – mathk

+0

添加了有问题的警告 – Raptor

+0

您似乎混淆了指针和值,请添加NSLog ligne。 – mathk

回答

6

对象被声明为在.h文件如下:

const float *vertices; 

尝试%d(整数),%@%f(双),但警告提示你想打印它的价值?

NSLog(@"%p: %f", vertices, * vertices); 

会打印出它的地址和浮动值在地址

为@KenThomases建议,您可能需要检查vertices不是NULL,如果你不能保证它。并打印出vertices中的所有值:

NSUInteger length = // length of vertices 

for (NSUInteger i = 0; i < length; ++i) { 
    NSLog(@"%f", vertices[i]); 
} 
+2

纠正注意事项:1)如果'vertices'为'NULL',则解除引用会崩溃。 2)由于'vertices'是复数,它很可能是一个指向数组的指针。你的建议只会记录第一个元素。你可以使用'vertices [1]'等等来记录更多的元素。你需要知道有多少元素。编译器和'NSLog()'都无法从普通指针中找出它。 –