[ Srđan Pavlović @ 20.10.2009. 04:58 ] @
| srdjan@Zverko:~/Desktop/C-Progs$ cat 1.c
#include <stdio.h>
/*
* Tell the compiler that we intend
* to use a function called show_message.
* It has no arguments and returns no value
* This is the "declaration".
*
*/
void show_message(void);
/*
* Another function, but this includes the body of
* the function. This is a "definition".
*/
main(){
int count;
count = 0;
while(count < 10){
show_message();
count = count + 1;
}
exit(0);
}
/*
* The body of the simple function.
* This is now a "definition".
*/
void show_message(void){
printf("hello\n");
}
srdjan@Zverko:~/Desktop/C-Progs$ gcc 1.c -o 1-p
1.c: In function ‘main’:
1.c:25: warning: incompatible implicit declaration of built-in function ‘exit’
srdjan@Zverko:~/Desktop/C-Progs$ ./1-p
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
srdjan@Zverko:~/Desktop/C-Progs$
Sta znaci ova nekompatibilnost (ovo je neki example sa net-a)? |
[ Srđan Pavlović @ 20.10.2009. 05:34 ] @
srdjan@Zverko:~$ gcc --version
gcc (Ubuntu 4.4.1-4ubuntu8) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
srdjan@Zverko:~$
Ako je bitno...
[ X Files @ 20.10.2009. 06:28 ] @
Pokušaj da dodaš:
#include <stdlib.h>
... i vidi da li se upozorenje javlja i dalje.
Mada, zašto ne koristiš jednostavno:
return 0;
odnosno:
return EXIT_SUCCESS;
(ovo EXIT_SUCCESS kao i EXIT_FAILURE naravno mozeš da koristiš i uz exit(...))
Dalje, po standardu:
main(void)
....treba da bude:
int main(void)
[ Srđan Pavlović @ 20.10.2009. 06:36 ] @
Ne znam C, povremeno krenem da ga učim pa batalim,
pa tako stalno... :)
Da, samo dodavanje stdlib-a je rešilo problem, hvala.
[ EArthquake @ 23.10.2009. 07:03 ] @
fora je u tome , sto da bi koristio neku funkciju , moras da ukljucis njenu deklaraciju u program
u ovom slucaju preko header fajla
u suprotnom kompajler ne moze da zna na koju si funkciju mislio
ovaj slucaj je specifican zato sto je exit() f-ja iz stdlib-a , tj standardne biblioteke , pa je gcc prepoznaje automatski , ali ti ipak javlja gresku , za slucaj da si ti hteo nesto drugo
naravno , ne treba se oslanjati na takve "feature" komapjlera , vec uvek ukljucivati biblioteke u kojima su funkcije definisane
Copyright (C) 2001-2024 by www.elitesecurity.org. All rights reserved.