asun, prepare to do A LOT of copying and pasting ;P lolOriginally Posted by quzah
asun, prepare to do A LOT of copying and pasting ;P lolOriginally Posted by quzah
Kleido-0, time to update your title thingy. Unless you're hoping for some negative repvvv The Red Means Happy!
If you understand what you're doing, you're not learning anything.
I could see people scrolling down the screen and saying themselves: "Where's the red!?" lol.
>And don't tell me it's off topic because you can put assembly into your C code.
It's off-topic because you can't do it portably. First, embedding assembly code into C source is a common extension, but not blessed by the standard. Second, assembly itself is dreadfully nonportable. Now, if the question mentioned a compiler, operating system, and architecture then we could get into mentioning assembly. Of course, it would still be off-topic because it isn't C.
>I was hoping you would do that :P
I have done that, just not with the code you linked to. In a previous life I implemented a large portion of the C run-time and standard library to work with a very broken OS.
My best code is written with the delete key.
this code does work.Code:int printf(const char *format, ... ); int main(void) { printf("a"); return 0; }
but i don't understand about
what is this code do??Code:int printf(const char *format, ... );
what does the format do??
thx dave_sinkula
>what is this code do??
It declares printf, which is approximately what including <stdio.h> would do.
My best code is written with the delete key.
Approximately? As far as printf() is concerned, isnt that all it would do?
>As far as printf() is concerned, isnt that all it would do?
How the standard headers are implemented isn't specified.
My best code is written with the delete key.
>What does this code do?Originally Posted by asun
It's called a prototype function. It lets int main know there is a function called int printf(const char *) somewhere. If you put the full printf function on top of the int main, then you don't need a prototype function. You could do this:
ORCode:#include <stdlib.h> #include <stdio.h> void bird(void) { puts("*whistle sound*"); } int main(void) { bird(); return 0; }
But you CAN'T do thisCode:#include <stdlib.h> #include <stdio.h> void bird(void); int main(void) { bird(); return 0; } void bird(void) { puts("*whistle sound*"); }
Because you get this on compiling:Code:#include <stdlib.h> #include <stdio.h> int main(void) { bird(); return 0; } void bird(void) { puts("*whistle sound*"); }
Because int main does not know where the void bird(void) function is.Code:kleid@Shiva:~/Programming/Laboratory$ gcc prototype.c prototype.c:9: warning: type mismatch with previous implicit declaration prototype.c:5: warning: previous implicit declaration of `bird' prototype.c:9: warning: `bird' was previously implicitly declared to return `int'
>What does the format do?
The const char *format says that the function printf() has an argument that's a char array that won't be changed (hence the const). format is a string filled with %i's %d's %g's %f's %s's. The %whatever is a way of formatting your string output. That's why the char array is named format. You could even like this:
There's my 2 cents.Code:int printf(const char *JDFLkjserjsdflJER, ... );