小编Car*_*rum的帖子

Obj-C中的静态全局变量?

// in ClassA.h  
static NSString *globalStr = @"HelloWorld";

@interface ClassA  
    ...  
@end

// in ClassB.h  
#include "ClassA.h"

// in ClassB.m  
...  
NSLog(@"The global string: %@", globalStr);
...
Run Code Online (Sandbox Code Playgroud)

在C++中,"static"应该表示变量或函数具有内部链接.
但是在这种情况下它用于共享变量,没有static关键字就会发生错误.

我很困惑,有人可以告诉我背后的概念吗?
谢谢!

linker static global-variables objective-c

0
推荐指数
1
解决办法
1068
查看次数

函数在ObjC for iPhone中返回一个数组

您好我正在尝试使此函数返回一个数组!这里出了什么问题?

-(char[10])print01:(int)int11{ //error: declared as method returning an array
    char arrayT[10];

    for(int i=0;i<8;i++)
    {
        if ((int1-n1)>=0){
            arrayT[i]='1';
            int1-=n1;
        }
        else 
            arrayT[i]= '0';
        n1=n1/2;
    }

    return arrayT[]; // incompatible types in return
}
Run Code Online (Sandbox Code Playgroud)

我想这样称呼它:

char array1[10] = [self print01:(int)int1]; //error: invalid initializer
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

iphone macos sdk objective-c

0
推荐指数
1
解决办法
2542
查看次数

x86汇编代码

谁能告诉我x86 ASM中的以下代码是什么?它只是一个较大文件的一部分,但只是这一点让我失望.

find_max:
  6 .LFB0:
  7         .cfi_startproc
  8         pushq   %rbp
  9         .cfi_def_cfa_offset 16
 10         movq    %rsp, %rbp
 11         .cfi_offset 6, -16
 12         .cfi_def_cfa_register 6
 13         movl    %edi, -20(%rbp)
 14         movl    -20(%rbp), %eax
 15         cltq
 16         movl    a(,%rax,4), %eax
 17         movl    %eax, -4(%rbp)
 18         movl    -20(%rbp), %eax
 19         movl    %eax, -8(%rbp)
Run Code Online (Sandbox Code Playgroud)

特别,

  • 第13行的%edi最初是什么?
  • 为什么代码引用-20(%rbp)?
  • 第16行究竟做了什么?
  • 切换32位寄存器和64位寄存器背后的智慧是什么(例如在第15行的情况下)?

我为了得到这个而拆解的C代码如下所示:

extern int a[];

int find_max(int n)
{
    int max = a[n];
    int pos = n;
    int x;

    while (n > 0)
    {
        n--;
        x …
Run Code Online (Sandbox Code Playgroud)

x86 assembly disassembly

0
推荐指数
1
解决办法
629
查看次数

SCNuFAST16 PRIuFAST16警告:格式为未知转换类型字符0x20

test.c: In function ‘main’:
test.c:10: warning: unknown conversion type character 0x20 in format
test.c:10: warning: unknown conversion type character 0x20 in format
test.c:12: warning: conversion lackstype at end of format
test.c:12: warning: unknown conversion type character 0xa in format
test.c:12: warning: conversion lacks type at end of format
test.c:12: warning: unknown conversion type character 0xa in format
Run Code Online (Sandbox Code Playgroud)

gcc test.c -o test

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc,char *argv[]){

    uint_fast16_t n_curve,n_pt;

    printf("Please enter new value \n");
    scanf( "% …
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
4148
查看次数

如何在cin之后得到一个空白行

我需要一行来将用户输入与结果分开.这是一门基础计算机科学课程.

cout << "Please enter (variable): ";
cin >> (variable);
cout << "\n\n:";
cout << "(results)" << endl;
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以获得cin之后的空白行,或者这是否可行?

c++

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

标签 统计

objective-c ×2

assembly ×1

c ×1

c++ ×1

disassembly ×1

global-variables ×1

iphone ×1

linker ×1

macos ×1

sdk ×1

static ×1

x86 ×1