编译提示:warning: ISO C89 forbids mixed declarations and code

在编译CSR8670程序的过程中,出现如下提示:

Running 'C:/ADK3.5/tools/bin/make -R BLUELAB=C:/ADK3.5/tools -f part2.release.mak C:/Users/fingertouch/Desktop/part2/main.o'...
Chip detected is gordon, default execution mode for this hardware is assisted
C:/ADK3.5/tools/bin/xap-local-xap-gcc-3.3.3 -BC:/ADK3.5/tools/lib/gcc-lib/xap-local-xap-assisted/3.3.3\ -mpu -mleaf-optim -mno-function-sizeof -mworkaround-b96516 -g -O -fno-builtin-memcpy -ansi -pedantic -Wall -Wmissing-prototypes -Wstrict-prototypes -Wsign-compare -Wredundant-decls -Werror -IC:/ADK3.5/tools/include/firmware -IC:/ADK3.5/tools/include/standard -IC:/ADK3.5/tools/include/profiles/BlueLab-6.5.2-Release -Wp,-MD,C:/Users/fingertouch/Desktop/part2/depend/main -Wp,-MQ,C:/Users/fingertouch/Desktop/part2/main.o  -I./ -c C:/Users/fingertouch/Desktop/part2/main.c -o C:/Users/fingertouch/Desktop/part2/main.o
C:/Users/fingertouch/Desktop/part2/main.c: In function `profile_handler':
C:/Users/fingertouch/Desktop/part2/main.c:46: warning: ISO C89 forbids mixed declarations and code
make: *** [C:/Users/fingertouch/Desktop/part2/main.o] Error 1
Finished.

在网上查了一下,发现是变量没有定义在程序块的开始位置导致的,调整一下程序语句,提示消失。

原程序语句:

static void profile_handler(Task task, MessageId id, Message message)
{
    switch(id)
    {
        case CL_INIT_CFM:
        {
            DEBUG(("CL_INIT_CFM
"));
            
            CL_INIT_CFM_T *msg = (CL_INIT_CFM_T*)message;
            
            if(msg->status == success)
            {
                CsrInternalCodecTaskData *codec = PanicUnlessMalloc(sizeof(CsrInternalCodecTaskData));
                CodecInitCsrInternal(codec, &simple_ag.task);
                AghfpInit ( &simple_ag.task, aghfp_handsfree_15_profile, aghfp_incoming_call_reject | aghfp_inband_ring);  
            }
            else
            {
                DEBUG((" CL_INIT_CFM failure : %d
", msg->status));
                Panic();
            }
            break;
        }
    }
}

调整后:

static void profile_handler(Task task, MessageId id, Message message)
{
    switch(id)
    {
        case CL_INIT_CFM:
        {
            CL_INIT_CFM_T *msg = (CL_INIT_CFM_T*)message;
            DEBUG(("CL_INIT_CFM
"));
            
            if(msg->status == success)
            {
                CsrInternalCodecTaskData *codec = PanicUnlessMalloc(sizeof(CsrInternalCodecTaskData));
                CodecInitCsrInternal(codec, &simple_ag.task);
                AghfpInit ( &simple_ag.task, aghfp_handsfree_15_profile, aghfp_incoming_call_reject | aghfp_inband_ring);  
            }
            else
            {
                DEBUG((" CL_INIT_CFM failure : %d
", msg->status));
                Panic();
            }
            break;
        }
    }
}

  

原文地址:https://www.cnblogs.com/fingertouch/p/4587958.html