c - 函数返回结构编译通过 gcc 失败,但通过 vc6.0 成功

标签 c gcc

<分区>

为什么gcc编译失败,vc6.0编译成功

gcc 版本 4.1.2 20070115 (SUSE Linux)

linux:~# cc t.c
t.c: In function ‘main’:

t.c:24: error: invalid use of non-lvalue array - printf((confFQDNtolower(&tFQDN)).strName);

代码:

#include <stdio.h>
#include <ctype.h>

typedef struct  {
    char strName[128];
    unsigned short wLen;
}T_FQDN;

T_FQDN confFQDNtolower(T_FQDN *ptFQDN)
{
    static T_FQDN tFQDN = {0};
    int i;

    tFQDN.wLen = ptFQDN->wLen;
    for (i = 0; i < ptFQDN->wLen; i++)
    {
        tFQDN.strName[i] = tolower(ptFQDN->strName[i]);
    }

    return tFQDN;
}

int main()
{
    T_FQDN tFQDN = {"a.B.c", 5};

    printf((confFQDNtolower(&tFQDN)).strName);

    return 0;
}

最佳答案

尝试

printf(&(confFQDNtolower(&tFQDN).strName[0]));

请在此处查看已接受的答案和评论,以了解为什么这会改变一切。 C - invalid use of non-lvalue array

关于c - 函数返回结构编译通过 gcc 失败,但通过 vc6.0 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21827366/

相关文章:

c - 尝试使用 pthread_create 时出错

c - 在 GCC 中编译时在 C 中编辑操作的 ASM 结果

c++ - 在 GCC、Clang 和 MSVC 中,有什么方法可以符合 C++98 而不是 C++03 吗?

c - 体系结构 x86_64 MAC GCC 的 undefined symbol

c - 初始化由 C 中的枚举索引的字符串数组

c - 引用 C 静态库中的文件

c - 为什么此函数中使用 Char 数据类型?

c - 从控制台应用程序调用 .DLL 函数时遇到问题

c++ - Linux - 运行 valgrind 时不显示源文件/行

c++ - 在多核 (linux) 中运行进程的命令行参数是什么