gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > question

#53464 - sparda - Thu Sep 08, 2005 4:40 pm

ok, if anyone can help me out with this, i would really appreciate it.


Can anyone tell me why this function works, even though it hasn't been defined, prototyped or anything? is it a keyword? i dont think it is because usually when i use keywords on my compiler(DEV-C++) they appear in bold, in this case it doesn't. I took this function from a tutorial at : http://www.webbesen.dk/gba/default.asp

function : memcpy( (u16 *)0x06014000, &ballData, sizeof(ballData) );

I've tested the function without any preprocessor directives or inclusions, just the MAIN function, AND IT STILL WORKS!! i dont understand. For example:

----------------------------------------------------------------------------------------

main()
{
int a,b,c;
memcpy(&a, &b, sizeof(c));

}

--------------------------------------------------------------------------------------
_________________
genius is 1% inspiration, 99% perspiration .

#53468 - Cearn - Thu Sep 08, 2005 4:52 pm

memcpy is not a keyword but a function, and could be one of the standard functions that pretty much have to be there. The declaration is probably 'build in' to the compiler itself, in the same same way that division code is (__divsi() or whatever the things are called). memcpy() is used for by the compiler for struct-copies bigger than ~50 bytes, so it could well be part of the build-in set.
It is perfectly possible to have functions that don't need declarations. main() doesn't for example. Also, in ancient history (say, 10 years), printf() didn't need necessarily need stdio.h to be included either.

#53502 - Touchstone - Thu Sep 08, 2005 8:43 pm

In C a function doesn't need to be prototyped. However the compiler might emit a warning. This will also work in C but not C++:
Code:
void main()
{
    doFunc();
}

void doFunc()
{
}

_________________
You can't beat our meat