logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[C]Funkcja dtostrf() - ostrzeżenie

Piotr Kania 15 Gru 2008 19:38 5081 6
REKLAMA
  • #1 5863502
    Piotr Kania
    Poziom 15  
    dlaczego mam takie ostrzeżenie 1wire.c:109: warning: passing argument 4 of 'dtostrf' makes pointer from integer without a cast

    a program zatrzymuje się na write_text(dtostrf(th, 2, 0, 2));

    
    ow_reset();
          ow_write_byte(0xCC);
          ow_write_byte(0x44);
          _delay_ms(1000);
          ow_reset();
          ow_write_byte(0xCC);
          ow_write_byte(0xBE);
          lsb = ow_read_byte();
          msb = ow_read_byte();
    	  th = ow_read_byte();
    	  tl = ow_read_byte();
    	  ow_reset();
    	  
    	   
    	  celcius =  msb << 8 | lsb ;
          celcius/=16;
          temp = msb << 4| lsb >> 4;
          write_command(0x01);
          unsigned char tab[6];
    	  LCD_xy(0,0);
    	  LCD_xy(0,0);
    	  write_text("Temperatura");
    	  LCD_xy(1,0);
          write_text(dtostrf(celcius, 3, 4, tab));
    	  uint8_t znak1[] = {0,14,10,14,0,0,0,0}; 
          LCD_DefineCharacter(0, znak1);
    	  LCD_xy(1,8);
    	  write_char(0); 
    	  write_text("C");
    	  write_text(" Th");
    	  write_text(dtostrf(th, 2, 0, 2));   (tu jest ten warning)
    


    zna ktoś przyczynę ?

    Poprawiłem tytuł - regulamin p.11
    [zumek]
  • REKLAMA
  • REKLAMA
  • #3 5863878
    Piotr Kania
    Poziom 15  
    oto zmienne

    char msb,lsb,th,tl,a,temp;
    float celcius;
  • REKLAMA
  • REKLAMA
  • #5 5864763
    Piotr Kania
    Poziom 15  
    float a; ?

    Dodano po 39 [sekundy]:

    nie sorry float th;
  • #6 5864795
    Freddie Chopin
    Specjalista - Mikrokontrolery
    dtostrf(celcius, 3, 4, tab)
    dtostrf(th, 2, 0, 2)

    znajdz roznice. potem porownaj to co napisales tutaj:

    dtostrf(th, 2, 0, 2)

    z tym:

    Cytat:

    char* dtostrf (double __val, char __width, char __prec, char * __s)
    The dtostrf() function converts the double value passed in val into an ASCII representationthat will be stored under s. The caller is responsible for providing sufficient storage in s.

    Conversion is done in the format '[-]d.ddd'. The minimum field width of the output string (including the '.' and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign.

    The dtostrf() function returns the pointer to the converted string s.

    http://linux.die.net/man/3/dtostrf

    sprawa tego, ze th jest typu char, a dtostrf jest przeznaczone dla typu zmiennoprzecinkowego pominmy. tak - to bezsenowne, skrajnie nieoptymalne, zajmujace ogromne ilosci kodu i czasu rozwiazanie, ale nie tutaj jest problem... nawiasem mowiac, to liczb calkowitych wymyslono inne funkcje do konwersji - itoa() dla przykladu...

    4\/3!!
  • #7 5865183
    piti___
    Poziom 23  
    Warning oznacza że argument 4 jest przez funkcje traktowany jako wskaznik z liczby całkowitej bez rzutowania (makes pointer from integer without a cast).

    Funkcja jako 4 argument powinna otrzymac wskaznik a nie stala.
REKLAMA