LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't CVI 7.1 compiler allow mixing declarations and statements?

I'm compiling CVI 7.1 code where I have function calls embedded in variable declarations.  How can I get C compiler to allow mixed statements and declarations?
 
Example:
int CVIFUNC InternationalFileDate(char filePath[], char dateString[], int bufferSize)
{
    time_t  time;
    VCAST_WRITE_TO_INST_FILE("001 017 001 ");
    int     error = 0;
    int     success;
    VCAST_WRITE_TO_INST_FILE("001 017 002 ");
    errChk( success = GetFileCLibTime(filePath, &time));
    VCAST_WRITE_TO_INST_FILE("001 017 003 ");
    if (success) {
        VCAST_WRITE_TO_INST_FILE("001 017 004 ");
        return InternationalDateString(time, dateString, bufferSize);
    }
    else {
        VCAST_WRITE_TO_INST_FILE("001 017 005 ");
        return 0;
    }
    VCAST_WRITE_TO_INST_FILE("001 017 006 ");
Error:
    VCAST_WRITE_TO_INST_FILE("001 017 007 ");
    return error;
}
 
0 Kudos
Message 1 of 5
(3,458 Views)
First: the language C doesn't permit mixing statements and declarations. This is a C++ 'enhancement'.

But this trick would do it here:

int CVIFUNC InternationalFileDate(char filePath[], char dateString[], int bufferSize)
{
    time_t  time;
    VCAST_WRITE_TO_INST_FILE("001 017 001 ");
   
    { // <--

        int     error = 0;
        int     success;
        VCAST_WRITE_TO_INST_FILE("001 017 002 ");
        errChk( success = GetFileCLibTime(filePath, &time));
        VCAST_WRITE_TO_INST_FILE("001 017 003 ");
        if (success) {
            VCAST_WRITE_TO_INST_FILE("001 017 004 ");
            return InternationalDateString(time, dateString, bufferSize);
        }
        else {
            VCAST_WRITE_TO_INST_FILE("001 017 005 ");
            return 0;
        }
        VCAST_WRITE_TO_INST_FILE("001 017 006 ");
    Error:
        VCAST_WRITE_TO_INST_FILE("001 017 007 ");
        return error;

    } // <--

}

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 2 of 5
(3,445 Views)

Thanks for your suggestion.  But I have a large code base which would make this fix very labor intensive and time consuming.

 

Regarding mixing declarations and statements, I believe ISO C99 allowed mixing of declarations and statements to move ANSI-C closer to C++.  I was hoping to import the latest Visual C or GNU C compiler, which I believe will support mixing declarations and statements. 

0 Kudos
Message 3 of 5
(3,421 Views)
C99 permits declarations anywhere within a block, not just at the head of a block before the first statement as with previous versions of C (including the native CVI C compiler).

It would be nice for NI to upgrade the native CVI C compiler to C99.  I wonder if they have any plans to do so.

As long as we're on the topic, I'd really like a realtime Java implementation (even if only compiled Java) and a native C++ compiler for CVI as well.

Real-time Java (RTSJ) is getting a lot of use these days, in everything from cellphones to unmanned aerial vehicles.
0 Kudos
Message 4 of 5
(3,406 Views)


   I'm interested too in an extension of CVI to C++ language! While I'm sceptical about Java....
0 Kudos
Message 5 of 5
(3,379 Views)