例如:
Bool NullFunc(const struct timespec *when, const char *who)
{
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
在C++中,我能够对/*...*/参数进行评论.但当然不是在C中,它给了我错误error: parameter name omitted.
我在尝试调用方法时遇到错误:
int box(int rows, int cols, int [rows][cols])
Run Code Online (Sandbox Code Playgroud)
从使用此调用的main方法:
box(arrayDimensions, arrayDimensions, array);
Run Code Online (Sandbox Code Playgroud)
但我不确定问题是什么.
谢谢.
在 C++17 标准中声明(强调我的):
“变量是由非静态数据成员或对象的引用声明引入的。变量的名称(如果有)表示引用或对象。”
来源:ISO/IEC 14882:2017 (C++17), §6/6 - “基本概念”
为什么是“如果有”?变量可以在 C++ 中省略名称吗?
如果我查看 cppreference:
“在 C++ 中,变量实际上只是为程序使用而保留的一点内存。您使用变量名来引用它,因此您无需担心它在内存中的位置(尽管您可以找到出它的内存地址,甚至可以指定它的位置,如果你愿意的话)。”
或者维基百科(我知道它不是最好的来源,但仍然很常见):
“在计算机编程中,变量或标量是一个存储地址(由内存地址标识)与相关的符号名配对,其中包含一些已知或未知的信息量,称为值。变量名是通常的方法根据上下文,除了引用变量本身之外,还引用存储的值。”
来源:https : //en.wikipedia.org/wiki/Variable_(computer_science)
这表示变量应始终提供与其关联的名称,无论引用的对象/值是否被它访问。
变量在 C++ 中是否可能没有名称?
如果是,如何以及在哪里(如果可能有多种情况)?
或者,如果我误解了某些东西,那么“如果有的话”如何解释?
有关的:
我正在浏览一个模板(在cloudpebble.net上),用于构建Pebble表盘并遇到以下代码:
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) {
(void)t; // NOOP?
(void)ctx; // NOOP?
display_time(t->tick_time);
}
void handle_init(AppContextRef ctx) {
(void)ctx; // NOOP?
window_init(&window, "Big Time watch");
window_stack_push(&window, true);
window_set_background_color(&window, GColorBlack);
resource_init_current_app(&APP_RESOURCES);
// Avoids a blank screen on watch start.
PblTm tick_time;
get_time(&tick_time);
display_time(&tick_time);
}
void handle_deinit(AppContextRef ctx) {
(void)ctx; // NOOP?
for (int i = 0; i < TOTAL_IMAGE_SLOTS; i++) {
unload_digit_image_from_slot(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我指出的线路用于什么目的?
我刚开始学习 C,我在给出的一个例子中遇到了这个,我知道这是一个函数原型,但我还没有理解的概念是这样一个事实
void function(char *);
Run Code Online (Sandbox Code Playgroud)
意味着当我最终声明该函数时,它将采用像这样的参数 char 指针参数
void function(char *arg){}
Run Code Online (Sandbox Code Playgroud)
?
c ×4
function ×2
arrays ×1
c++ ×1
declaration ×1
gcc ×1
gcc-warning ×1
identifier ×1
methods ×1
pebble-watch ×1
prototype ×1
reference ×1
variables ×1