- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Here are the 2 programs with very minor change.
Practice.c
#include <stdio.h>
#define P (i+j)
main()
{
int i,j,k=0;
printf("\nI = ");
scanf("%d",&i);
printf("\nJ = ");
scanf("%d",&j);
k=P;
printf("\nValue of Defined Macro P = %d\n",k);
#undef P
printf("\nValue of Undefined Macro P = %d\n",k);
}
上述程序的输出是:
I = 5
J = 9
Value of Defined Macro P = 14
Value of Undefined Macro P = 14
New.c
#include <stdio.h>
#define P (i+j)
main()
{
int i,j,k=0;
printf("\nI = ");
scanf("%d",&i);
printf("\nJ = ");
scanf("%d",&j);
k=P;
printf("\nValue of Defined Macro P = %d\n",P);
#undef P
printf("\nValue of Undefined Macro P = %d\n",P);
}
上述程序的输出是:
Practice.c: In function 'main':
Practice.c:15:48: error: 'P' undeclared (first use in this function)
printf("\nValue of Undefined Macro P = %d\n",P);
^
Practice.c:15:48: note: each undeclared identifier is reported only once for eac
h function it appears in
现在我想知道为什么Practice.c
编译执行成功了,我用变量k
来显示输出,为什么 New.c
直接使用宏模板 P
显示错误?
最佳答案
#define
在编译期间替换代码中的字符串。所以当编译器处理
#define P (i + j)
,它用 (i + j)
替换它看到的每个 P 实例,直到到达它读取的位置 #undef P
。这告诉编译器停止用 (i + j)
替换 P
。
因此,P
的最后一个实例(在 #undef
语句之后)没有被替换,并且由于上面的代码中没有声明变量 P,它会导致错误。
这在第一个程序中不是问题,因为您已经在行中声明了 k
int i,j,k=0;
关于c - 使用#undef 预处理器指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24339106/
几年前,当我最初学习 Perl 时,我发现自己想说一些类似的话: sleep .07; 但这实际上行不通。 有人教我使用: select undef, undef, undef, .07; 反而。 我
undef $x is different from $x = undef .我的印象是两者都会触发垃圾收集和释放内存,但似乎 $x = undef 不会这样做。 这是语言错误吗?在执行 $x = u
我正在使用铁路 api 构建 Web 应用程序,在提交火车号时我试图显示数据但出现上述错误。实际上我在获取数据时使用了 if else 条件。 下面是代码。 import React, { Com
我在 Perl 中有以下(从错误中理想化的)简短脚本: my %metadata = undef; if (defined %metadata) { print "defined"; } 出于
Julia 中检查数组条目是否为 #undef 的最佳方法是什么? 例子: julia> a = Array(Vector,2) julia> isdefined(a[1]) # fails jul
我有一个全局扩展,它定义了一个名为“is”的方法。我遇到的问题是 ESLink 将其标记为“no-undef”;尽管它在运行时可用。 禁用规则对我来说不是一个选择。我宁愿定义它以便 ESLint 可以
在 Perl 中读取配置文件时,可能会出现某行无效且不需要将其添加到我的有效行数组中的情况。由于我在这里使用 for 循环,因此即使无效行也会创建一个 undef 条目。之后我怎样才能将它们全部删除?
有时候我想写: my $var = shift // undef; # argument is optional # or my $va
我定义了一堆宏,它们只在项目的一小部分范围内发挥作用。我想取消定义它们,这样它们就不会污染全局命名空间,但 Visual Studio 仍然会在其他文件中的#undef 之后确认它们的存在。即: //
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: undef - Why would you want to undefine a method in rub
我正在将一些参数传递给函数,其中一个可能未定义。 $a = ($config->function(param('a'),'int')); 我的模块包含一个如下所示的函数: sub function{
我在一个数组中定义了一些元素: my @arrTest; $arrTest[0]=1; $arrTest[2]=2; #Result for @arrTest is: (1, undef, 2) if
有什么办法可以从 no-undef 中排除特定模式吗?错误。我试过 'no-undef': [2, { ignoreBuiltinGlobals: ['app'] }]哪里app是由 webpack.
我使用教程来学习 React,但很快就卡住了。在教程中,他们使用了这段代码: import React, { Component } from "react"; class Counter exten
我有一个 Moose 类,它的属性起到一定的作用: has foo => (is => 'rw', does => 'Foo::Bar'); 现在我如何更改声明以允许 undef ?我试过 does
我今天似乎很傻,或者我有一个很奇怪的问题。请考虑以下代码: #!/usr/bin/perl use strict; use warnings; use warnings::unused; use wa
我是 react 新手。我的应用程序运行正常,但添加 eslint(airbnb) 后,我的应用程序无法编译。 export default class HelloWorldComponent ext
尝试编译我的应用程序时出现以下错误 - 'getRestaurants' 未定义 no-undef 我无法查明为什么没有为 zipCodeToCoords 定义 getRestaurants 我有一个
我制作了cardList,想通过 map 将卡片添加到cardlist中,但出现此错误 import React from 'react'; import Card from './Card'; co
我想在表的列中插入 null。 哪一个代表 null? undef 或空字符串 ''。 应该使用哪一个,为什么?我知道已定义并且我可以检查它。 但我更多的是从数据库的角度来看。 哪一个更恰本地表示nu
我是一名优秀的程序员,十分优秀!