- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
int main()
{
long int i,t,n,q[500],d[500],s[500],res[500]={0},j,h;
scanf("%ld",&t);
while(t--)
{
scanf("%ld %ld",&n,&h);
for(i=0;i<n;i++)
scanf("%ld %ld",&d[i],&s[i]);
for(i=0;i<h;i++)
scanf("%ld",&q[i]);
for(i=0;i<h;i++)
{
for(j=0;j<n;j++)
{
res[j]=d[j]+q[i]*s[j];
}
j=cal(res,n,q[i],s);
printf("%ld\n",j);
}
}
return 0;
}
long int cal(int res[],int n,int q,int s[])
{
long int i,max=0,p,pos=0;
for(i=0;i<n;i++)
{
if (max==res[i])
{
pos=add(res,s,pos,i,q);
max=res[pos];
}
if (res[i]>max)
{
max=res[i];
pos=i;
}
}
return pos;
}
每当我将变量作为 int
时,它工作正常,但如果我将变量声明为 long int
,我会收到警告消息“可疑指针转换"在函数调用中 — 在行中:
(j=cal(res,n,q[i],s));
能解释一下原因吗?
最佳答案
给定:
long int i,t,n,q[500],d[500],s[500],res[500]={0},j,h;
j=cal(res,n,q[i],s);
和long int cal(int res[],int n,int q,int s[])
您正在尝试将数组 long res[500]
传递给需要 int
数组的函数。即使 sizeof(int) == sizeof(long)
在您的机器上,类型也不同 — 而且大小在我的机器上肯定不同。
如果你在 Windows(32 位或 64 位)或 32 位 Unix 上,你会摆脱它,但如果你迁移到 LP64 64 位环境,一切都会崩溃.
这就是为什么它是“可疑的指针转换”。这不是犹太洁食;它不可靠;它恰好适用于您的环境(但出于可移植性原因,它非常可疑)。
But why is it giving a warning as "suspicious pointer conversion" (instead of the expected message as "L-Value required")?
我不确定您为什么期望出现 l-value required
错误。请记住,当您调用函数时,数组会衰减为指针,因此您的函数声明也可以写成 long cal(int *res, int n, int q, int *s)
,并且您是传递 long res[500]
,它会自动更改为 long *
(就像您编写了 &res[0]
),所以您重新传递一个 long *
,而 int *
是预期的,你可能会逃脱它(因此是“可疑的”,而不是更严重的事情)。
考虑代码:
long res[500];
long cal(int res[]);
int main(void)
{
return cal(res);
}
64 位机器上的 GCC 4.7.1(和 64 位编译)说:
x.c: In function ‘main’:
x.c:6:5: warning: passing argument 1 of ‘cal’ from incompatible pointer type [enabled by default]
x.c:2:6: note: expected ‘int *’ but argument is of type ‘long int *’
(我不经常看到人们写 long int
而不仅仅是 long
,所以我采用了删除 int
from long int
. 你是对的,long int
是合法的并且和 long
是一样的;大多数人不会写多余的字,仅此而已。)
关于c - 采取 long int 时的可疑指针转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15318787/
继this q about GADTs之后,我正在尝试构建一个 EDSL(对于本文中的示例),但没有 GADT。我已经找到了一些可以避免 AST 数据类型加倍的方法;但相反,它似乎将代码加倍。所以我尝
我正在使用 compose 实现 MVI。为了让我遵循正确的事件循环,我需要通过我的 View 模型传播点击事件,然后观察副作用。我看过一些实现,它们都使用 LaunchedEffect(true)
有没有办法使用Python对日志文件中的“可疑时间”进行有效的二进制搜索? 我有一个日志文件,其条目如下: 02:38:18 0 RcvTxData - 11 : Telegram receive
一些黑客可以访问我的数据库,我将找出漏洞;我无权访问服务器日志。我制作了这段代码来保存文本文件中的可疑查询: function query($query) { $file = 'sqllog.txt'
问题背景: 日常对Sql Server 2005关系数据库进行操作时,有时对数据库(如:Sharepoint网站配置数据库名Sharepoint_Config)进行些不正常操作如数据库在读写时而无
1、出错情况 有些时候当你重启了数据库服务,会发现有些数据库变成了正在恢复、置疑、可疑等情况,这个时候DBA就会很紧张了,下面是一些在实践中得到证明的方法。 在一次重启数据
我在尝试解决这段短代码中的运行时段错误时遇到了麻烦。我怀疑这与代码中使用 system() 和 strcpy() 有关,但由于我没有遇到此类错误的经验,所以我不确定该怎么做,而且到目前为止我还没有找到
我正在尝试按照 NutchTutorial 运行基本爬网: bin/nutch crawl urls -dir crawl -depth 3 -topN 5 所以我已经安装了 Nutch,并使用 So
我注意到,当我通过浏览器打开 CSS 时,我看到我所有的图像都预先设置了一些 IP。它看起来像这样: url(http://64.19.142.11/www.mydomain.com/i/pgBg.p
我是一名优秀的程序员,十分优秀!