有人能找到错误 "a value of type "void" cannot be assigned to an entity of type "int" " in VScode 的原因吗?
Can some one please find the reason for the error "a value of type "void" cannot be assigned to an entity of type "int" " in VScode?
代码如下:
ssize_t readline(int fd, void *buf, size_t maxlen)
{
char c;
char * bufp=buf;
int n;
for(n = 0; n < maxlen - 1; n++)
{
int kk;
if((kk = read_or_die(fd, &c, 1)) == 1) // **Intellisense throws error here**
{
*bufp++ = c;
if(c == '\n')
break;
}
else if (kk == 0)
{
if(n == 0)
return 0;
else
break;
}
else
return -1;
}
bufp = '[=13=]';
return n;
}
函数的定义read_or_die定义如下:
#define read_or_die(fd, buf, count) \
({ssize_t rc = read(fd, buf, count); assert(rc >= 0); rc: })
从这个link我了解到rc
是从read_or_die ()
返回的。显然,rc
是 ssize_t
类型而不是 void.
为什么 VScode intellisense 在 if((kk = read_or_die(fd, &c, 1)) == 1)
抛出这个错误?
在宏的末尾添加分号是解决方案。
#define read_or_die(fd, buf, count) \
({ssize_t rc = read(fd, buf, count); assert(rc >= 0); rc; })
代码如下:
ssize_t readline(int fd, void *buf, size_t maxlen)
{
char c;
char * bufp=buf;
int n;
for(n = 0; n < maxlen - 1; n++)
{
int kk;
if((kk = read_or_die(fd, &c, 1)) == 1) // **Intellisense throws error here**
{
*bufp++ = c;
if(c == '\n')
break;
}
else if (kk == 0)
{
if(n == 0)
return 0;
else
break;
}
else
return -1;
}
bufp = '[=13=]';
return n;
}
函数的定义read_or_die定义如下:
#define read_or_die(fd, buf, count) \
({ssize_t rc = read(fd, buf, count); assert(rc >= 0); rc: })
从这个linkrc
是从read_or_die ()
返回的。显然,rc
是 ssize_t
类型而不是 void.
为什么 VScode intellisense 在 if((kk = read_or_die(fd, &c, 1)) == 1)
抛出这个错误?
在宏的末尾添加分号是解决方案。
#define read_or_die(fd, buf, count) \
({ssize_t rc = read(fd, buf, count); assert(rc >= 0); rc; })