C:被调用函数中的参数错误

时间:2017-12-20 22:19:06

标签: c

一般问题:

在main中我使用参数调用函数dd_draw_string(),如下所示。 问题是参数长度不是以正确的方式传递的。 因此,当我调用length = 6的函数并在被调用函数中查找带有断点的函数时,现在该参数的值为length = 4294967296(0xffff ffff)。

它不是完整的代码,但它应该足以显示我的问题。

font.h:

/*
 * font.h
 */

#ifndef FONT_H
#define FONT_H

#include "stdint.h"

void dd_draw_string(Color* color, uint32_t x, uint32_t y,  char* c, uint32_t length);

#endif /* FONT_H */

主:

#include "font.h"
int main() {

    init();

    while (1)
    {
        Color zero = BLUE;
        char bla[] = "hure";
        uint32_t laenge = 6;
        dd_draw_string(&zero, POSITION_NEXTTO_GRAPH_X, POSITION_CURSORX1_TEXT_Y, bla, laenge); //Cursor X1
     }
}

font.c

void dd_draw_string(Color* color, uint32_t x, uint32_t y, char* c, uint32_t length)
{

    uint8_t current_index;

    /*
     * switch over handed y position
     */
    switch(y)
    {
    case POSITION_BELOW_GRAPH_Y:
                if(x == POSITION_NEXTTO_GRAPH_X && length == FIELD_TIME_LENGTH)
                {
                    for(current_index = 0; current_index < FIELD_TIME_LENGTH; current_index++)
                    {
                        /*
                         * delete old char at current_index -> write = false
                         */
                        dd_draw_char(color, POSITION_TIME_TEXT_X + current_index * FONT_COLUMNS,
                                     POSITION_TIME_TEXT_Y, field_time[current_index], false);
                        /*
                         * update old char to current char in field
                         */
                        field_time[current_index] = c[current_index];
                        /*
                         * draw current char at display
                         */
                        dd_draw_char(color, POSITION_TIME_TEXT_X + current_index * FONT_COLUMNS,
                                     POSITION_TIME_TEXT_Y, field_time[current_index], true);
                        }
                }
                break;

顺便说一下,我用TM4C1294NCPDT进行编程,但我认为这是一个普遍的C问题。

0 个答案:

没有答案