标签: extern

如何声明extern typedef结构?

我有两个c文件,foo.c的功能和test_foo.c,它们测试foo.c的功能.

有没有办法BAR在不使用头文件的情况下访问test_foo.c中foo.c中定义的struct typedef ?到目前为止,我能够避免使用啊文件,因此整个程序将由foo.c组成.谢谢.

foo.c   
typedef struct BAR_{...} bar;
BAR *bar_new(...) {..}

test_foo.c
extern BAR *bar_new(...)
Run Code Online (Sandbox Code Playgroud)

error: expected declaration specifiers or ‘...’ before ‘BAR’

c extern

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

如何链接两个nasm源文件

我有一个文件定义了非常基本的IO函数,我想创建另一个使用该文件的文件.

有没有办法将这两个文件联系起来?

prints.asm:

os_return:
    ;some code to return to os
print_AnInt:
    ;some code to output an int, including negatives - gets param from stack
print_AChar:
    ;some code to output a char - gets param from stack
Run Code Online (Sandbox Code Playgroud)

usingPrintTest.asm:

main:
   push qword 'a'
   call print_AChar ;gets this from prints.asm somehow (that's my question)
   call os_return   ;and this too..
Run Code Online (Sandbox Code Playgroud)

注意这些不是实际的文件......它们只是用于解释我的问题:)

谢谢!

compiler-construction assembly linker nasm extern

6
推荐指数
1
解决办法
4124
查看次数

如何在Objective C中使用静态变量(BOOL)

我来自C#背景,我很难弄清楚如何在Objective C中使用静态变量(在我的例子中是BOOL).我的问题是:

  1. 我应该在哪里声明我的静态变量.
  2. 如何从另一个类访问(设置其值).
  3. 我是否需要使用extern关键字.

iphone static boolean objective-c extern

6
推荐指数
1
解决办法
4766
查看次数

外部未命名结构对象定义

我有一个“unnamed-struct”类型的全局对象,我正在尝试定义它。我不想用这种无用的类型污染我的全局命名空间(它只会使用一次)。

全局.h

extern struct {

    int x;

} A;
Run Code Online (Sandbox Code Playgroud)

有没有正确的方法来定义这样的对象?
我正在尝试这个:

全局.cpp

struct {

    int x;

} A = { 0 };
Run Code Online (Sandbox Code Playgroud)

但是 VS2012 抛出“错误 C2371:'A':重新定义;不同的基本类型”。谢谢。

c++ struct global-variables extern

6
推荐指数
1
解决办法
2067
查看次数

一个位于函数中的外部变量?

根据维基百科:

http://en.wikipedia.org/wiki/External_variable

外部变量也可以在函数内声明.

在函数中声明外部变量的目的是什么?它也必须是静态的吗?

c++ extern

6
推荐指数
1
解决办法
778
查看次数

翻译单元中的`static`定义和`extern声明`的顺序

我无法理解为什么这不起作用.

extern int i;

int main()
{
  printf(" %d ", i);  
}

static int i =3;
Run Code Online (Sandbox Code Playgroud)

此外,这不起作用:

extern int i;

static int i =3;

int main()
{
  printf(" %d ", i);  
}
Run Code Online (Sandbox Code Playgroud)

但是如果staticextern declaration它工作之前定义了变量:

static int i =3;

extern int i;

int main()
{
  printf(" %d ", i);  
}
Run Code Online (Sandbox Code Playgroud)

正如我所知道的extern int i那样,i它存在于其他地方,在这里它看起来如何(int i)

但是,其他地方意味着:

1)也许,稍后在same翻译单元中指出global variable.

2)也许,在一些other翻译单位.

我认为即使(1)将范围 …

c static extern

6
推荐指数
1
解决办法
1016
查看次数

我们可以使用Google Closure Compiler从完整的.js文件创建外部程序吗?

我想知道是否需要手动编写Google闭包编译器的外部文件.我还没有看到任何关于从我的.js文件生成这些文件的可能性.手动创建所有外部设备是相当多的工作,它也容易出错(即错误的参数定义,因为它随时间变化......)

所以我想知道是否有一个Linux工具(命令行)用于此目的.如果没有,是否有办法将.js与extern文件进行比较,这样我至少可以确保它们是同步的.

javascript extern google-closure-compiler

6
推荐指数
1
解决办法
122
查看次数

为什么"extern int&c;" 工作正常?

在C++中,必须初始化引用变量.int&a; //错误

static int &b; // Error
Run Code Online (Sandbox Code Playgroud)

extern int &c; // No error
Run Code Online (Sandbox Code Playgroud)

为什么编译器没有给出extern说明符引用的错误?

c++ variables reference extern

6
推荐指数
3
解决办法
231
查看次数

C++:使用内部链接向前声明 const

我想转发声明一个 const 变量而不给它外部链接。然而,在我看来,这是不可能的,因为extern关键字同时意味着“这具有外部链接”和“这是一个变量声明,而不是定义”,而且我无法得到一个没有另一个:

//// main.cpp: ////

extern const char table[256];    // forward declaration. External linkage.
// const char table[256];        // Error: table requires an initializer
// static const char table[256]; // Same error

// foo uses table so I need it forward declared:
char foo()
{
    // uses table
}

const char table[256] = {...}; // Actual definition
Run Code Online (Sandbox Code Playgroud)

我的理解正确吗?有什么解决方法吗?

c++ constants extern linkage

6
推荐指数
1
解决办法
840
查看次数

为什么 const int 需要 extern 而 const char* 不需要

我对为什么在我的 extern.cpp 文件的定义中需要extern或不需要intvs感到困惑char*。我有以下测试程序:

// extern.cpp
extern const int my_int = 1;
const char* my_str = "FOO";
Run Code Online (Sandbox Code Playgroud)
// main.cpp
#include <iostream>

extern const int my_int;
extern const char* my_str;

int main() {
  std::cout << my_int;
  std::cout << my_str;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我删除externfromextern const int my_int = 1;那么我得到undefined reference to 'my_int'. 如果我将 extern 添加到const char* my_str = "FOO";然后我会收到警告'my_str' initialized and declared 'extern'。我为什么需要externmy_int,但将它添加到 …

c++ extern c++17

6
推荐指数
1
解决办法
148
查看次数