SDL_main error

When I create the main function without args names for avoid warnings of
unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{

}

I can solve the problem using main(int argc, char **argv) but warnings
not are my friends.

What is the problem? Is there one?On Thursday, February 28, 2002, at 03:50 AM, samsaga2 wrote:

When I create the main function without args names for avoid warnings
of unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{
? …
}

I can solve the problem using main(int argc, char **argv) but warnings
not are my friends.

For avoid warnings I create main function without name parameters, but
then, SDL doesn’t found main function at link.

El dj, 28-02-2002 a las 14:24, David Leimbach escribi?:

What is the problem?  Is there one?On Thursday, February 28, 2002, at 03:50 AM, samsaga2 wrote:

> When I create the main function without args names for avoid warnings 
> of unused parameters compilers tell me undefined reference to SDL_main
>
> int main(int, char **)
> {
>   ...
> }
>
> I can solve the problem using main(int argc, char **argv) but warnings 
> not are my friends.


_______________________________________________
SDL mailing list
SDL at libsdl.org

http://www.libsdl.org/mailman/listinfo/sdl

I believe the problem is that he wants to be able to declare main() as
int main (void) or something; but no, you can’t do that because your
main() function is actually wrapped by SDL. When you run your SDL
program, the first routine run is not your main(), but SDL’s - it then
calls yours, which has to be defined as int main (int, char **) for it
to be able to find it. It’s done like this so that platform-specific
initialisation can be taken care of for you in a transparent fashion.

So the answer is… too bad. Make some sort of trivial usage out of argc
and argv if the warnings bother you. Very few programs don’t process any
command line arguments; in the UNIX world it’d be unthinkable :wink:

Maybe even just add a command line flag “/debug” or something that
enables the output of ridiculous amount of debugging information. It’ll
probably come in handy one day down the track - and in the meantime
you’ll have solved your “problem” :-)On Thu, Feb 28, 2002 at 07:24:24AM -0600, David Leimbach wrote:

On Thursday, February 28, 2002, at 03:50 AM, samsaga2 wrote:

When I create the main function without args names for avoid warnings
of unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{
? …
}

I can solve the problem using main(int argc, char **argv) but warnings
not are my friends.

What is the problem? Is there one?


Mike.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020228/57051491/attachment.pgp

Try
int main (int argc, char * argv [])

SDL_Main needs to match the function signature with these
parameters.

Please don’t ever code things like
void main (void)
main (void)
main ()
int main (void)

or any permutation of the above.

the two correct versions of main are and have always been:
int main ()
and
int main (int argc, char * argv [])

If you do anything else you shouldn’t expect it to work as nothing else has ever been standard C or C++ for
that matter.

When I create the main function without args names for avoid warnings
of unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{
? …
}

I can solve the problem using main(int argc, char **argv) but warnings
not are my friends.

What is the problem? Is there one?

I believe the problem is that he wants to be able to declare main() as
int main (void) or something; but no, you can’t do that because your
main() function is actually wrapped by SDL. When you run your SDL
program, the first routine run is not your main(), but SDL’s - it then
calls yours, which has to be defined as int main (int, char **) for it
to be able to find it. It’s done like this so that platform-specific
initialisation can be taken care of for you in a transparent fashion.

So the answer is… too bad. Make some sort of trivial usage out of argc
and argv if the warnings bother you. Very few programs don’t process any
command line arguments; in the UNIX world it’d be unthinkable :wink:

Maybe even just add a command line flag “/debug” or something that
enables the output of ridiculous amount of debugging information. It’ll
probably come in handy one day down the track - and in the meantime
you’ll have solved your “problem” :slight_smile:

Mike.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: replyAll
Type: application/pgp-signature
Size: 241 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020228/b58fb82e/attachment.pgp> On Thu, Feb 28, 2002 at 07:24:24AM -0600, David Leimbach wrote:

On Thursday, February 28, 2002, at 03:50 AM, samsaga2 wrote:

When I create the main function without args names for avoid warnings of
unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{

}

I can solve the problem using main(int argc, char **argv) but warnings
not are my friends.

You can do this:

int main(int argc, char **argv)
{
argc;
argv;
return 0;
}

If your compiler is especially pedantic and Wall, you can do this:

int main(int argc, char **argv)
{
argc = argc;
argv = argv;
return 0;
}

FYI, int main(int, char **) should have the same signature as
int main(int a, char **b)
The fact that it doesn’t makes me wonder what’s happening with
your compiler…

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

the two correct versions of main are and have always been:
int main ()
and
int main (int argc, char * argv [])

Oops, that’s probably it… the difference between:
int main(int, char *)
and
int main(int, char
[])

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hello Sam,

  I'll post my empty project tomorrow morning ;)
  + Makefile ;)
  
  I wish this will help ;)

  ( I'll be DAD!!!! So I don't have plenty of times
    theses days.... )

And by the way, can you check my devel site ?

dawn.linux-site.net

It’s empty, but send comment anyway :wink:

Thx!

Thursday, February 28, 2002, 11:01:21 AM, you wrote:

the two correct versions of main are and have always been:
int main ()
and
int main (int argc, char * argv [])

SL> Oops, that’s probably it… the difference between:
SL> int main(int, char *)
SL> and
SL> int main(int, char
[])

SL> See ya,
SL> -Sam Lantinga, Software Engineer, Blizzard Entertainment

SL> _______________________________________________
SL> SDL mailing list
SL> SDL at libsdl.org
SL> http://www.libsdl.org/mailman/listinfo/sdl--
Best regards,
mgirard mailto:@Mathieu_Girard

Well, if you look at the code, you’ll see they redefined main to SDL_main… It’s also written in the doc if I remember correctly.

Anyway, having warnings is not necessarly a bad thing, as long as you take the time to verify their meanings…

Toxic Avenger----- Original Message -----
From: samsaga2
Newsgroups: loki.open-source.sdl
To: Lista de SDL
Sent: Thursday, February 28, 2002 4:50 AM
Subject: [SDL] SDL_main error

When I create the main function without args names for avoid warnings of unused parameters compilers tell me undefined reference to SDL_main

int main(int, char **)
{

}

I can solve the problem using main(int argc, char **argv) but warnings not are my friends.