0

我有这个工作正常的功能:

void testeStatic2()
{
    static char elementos[8][128];
    const int qtdCol = 128;
    const int qtdLn = 8;

    printf("\n");

    char* pLinhas[qtdCol];
    int i = 0;
    for (i = 0; i < qtdLn; i++)
        pLinhas[i] = elementos[i];

    Fila_Init(&TELIT_dadosRecebidos, qtdLn, qtdCol, pLinhas);
}

我无法以更简单的方式重新创建此代码,因此,如果可能的话,忽略其余代码,问题是尽管它有效,但如果我取出printf("\n")它会给我一个执行时间错误。有人对此有任何想法吗?

谢谢...

4

1 回答 1

0

Just making pLinhas as static makes it to work fine. I suppose the problem was reference to nonexistent pointers after the end of function scope. So, this code was tested and works!

void FilaInit()
{   int i = 0;
    static char elementos[8][128];
    static char * pLinhas[8];

    for (i = 0; i < 8; i++)
        pLinhas[i] = &elementos[i][0];

    Fila_Init(&TELIT_dadosRecebidos, 8, 128, pLinhas);
} 

A detail is that pLinhas is an array of pointers to char, an array of pointers to strings. Its size is 8*4 bytes. Other point is that I must to use constant integer to declare pLinhas.

I would like to emphasize this solution...I have searched a lot this kind of structured data. It's very interesting in cases where you cannot use malloc, like embedded applications, but need to create more than one queue with different sizes.

For those who want to use this solution, I've created this project on google code: Qwoma. It would be a great pleasure to receive critics and ideas to this simple project.

Thanks everyone!

于 2013-07-10T01:54:52.063 回答