Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

main mit drei Parametern?

0 views
Skip to first unread message

Robert Hartmann

unread,
Oct 7, 2009, 10:27:16 AM10/7/09
to
Hallo zusammen,

Ich hab mal in http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
gestᅵbert und bin darauf gestoᅵen:


-Wmain
Warn if the type of `main' is suspicious. `main' should be a
function with external linkage, returning int, taking either zero
arguments, two, or three arguments of appropriate types.


Habt Ihr ein sinnvolles Beispiel
fᅵr eine main mit drei Argumenten?

Gruᅵ Robert

Joachim Schmitz

unread,
Oct 7, 2009, 10:46:12 AM10/7/09
to


Das 3. Argument ist eine gᅵngige Eweiterung des Standards und ᅵblicherweise
ein char** auf's Environment, alle Environment Variablen und ihre Werte.

Tschᅵ, Jojo

Joachim Schmitz

unread,
Oct 7, 2009, 10:53:33 AM10/7/09
to

Beispiel hier:

// Parsing_C_Commandline_args.c
// ARGS.C illustrates the following variables used for accessing
// command-line arguments and environment variables:
// argc argv envp
//

#include <stdio.h>

int main( int argc, // Number of strings in array argv
char *argv[], // Array of command-line argument strings
char **envp ) // Array of environment variable strings
{
int count;

// Display each command-line argument.
printf_s( "\nCommand-line arguments:\n" );
for( count = 0; count < argc; count++ )
printf_s( " argv[%d] %s\n", count, argv[count] );

// Display each environment variable.
printf_s( "\nEnvironment variables:\n" );
while( *envp != NULL )
printf_s( " %s\n", *(envp++) );

return;
}


Gefunden bei http://msdn.microsoft.com/en-us/library/a1y7w461.aspx

Tschᅵ, Jojo

Juergen Ilse

unread,
Oct 7, 2009, 11:00:25 AM10/7/09
to
Hallo,

> gestöbert und bin darauf gestoßen:


>
> -Wmain
> Warn if the type of `main' is suspicious. `main' should be a
> function with external linkage, returning int, taking either zero
> arguments, two, or three arguments of appropriate types.
>
> Habt Ihr ein sinnvolles Beispiel

> für eine main mit drei Argumenten?

Das kommt aus der "POSIX-Ecke" und der dritte Parameter ist ein Pointer
auf das Environment.

Tschuess,
Juergen Ilse (jue...@usenet-verwaltung.de)
--
Ein Domainname (auch wenn er Teil einer Mailadresse ist) ist nur ein Name,
nicht mehr und nicht weniger ...

Robert Hartmann

unread,
Oct 8, 2009, 4:29:19 AM10/8/09
to
Hallo Joachim,

Joachim Schmitz schrieb:


> Joachim Schmitz wrote:
>> Robert Hartmann wrote:

[...]


>>>
>>> Habt Ihr ein sinnvolles Beispiel
>>> fᅵr eine main mit drei Argumenten?

[...]


> Beispiel hier:
>
> // Parsing_C_Commandline_args.c
> // ARGS.C illustrates the following variables used for accessing
> // command-line arguments and environment variables:
> // argc argv envp
> //
>
> #include <stdio.h>
>
> int main( int argc, // Number of strings in array argv
> char *argv[], // Array of command-line argument strings
> char **envp ) // Array of environment variable strings
> {
> int count;
>
> // Display each command-line argument.
> printf_s( "\nCommand-line arguments:\n" );
> for( count = 0; count < argc; count++ )
> printf_s( " argv[%d] %s\n", count, argv[count] );
>
> // Display each environment variable.
> printf_s( "\nEnvironment variables:\n" );
> while( *envp != NULL )
> printf_s( " %s\n", *(envp++) );
>
> return;
> }
>
>
> Gefunden bei http://msdn.microsoft.com/en-us/library/a1y7w461.aspx

Danke dir.

Gruᅵ Robert

Stefan Scholl

unread,
Oct 8, 2009, 7:02:02 AM10/8/09
to
Joachim Schmitz <nospa...@schmitz-digital.de> wrote:
> printf_s( "\nCommand-line arguments:\n" );

Wo kommt denn printf_s() pl�tzlich her?


Michael Karcher

unread,
Oct 8, 2009, 8:27:49 AM10/8/09
to
Stefan Scholl <ste...@no-spoon.de> wrote:
> Wo kommt denn printf_s() plötzlich her?

Microsoft. Die haben bei vielen Standardfunktionen, von denen sie
meinten, dass die Spezifikation im Standard denen nicht passt, weil
sie z.B. zu leicht falsch einzusetzen sind, so dass es zu Buffer
Overruns kommt, leicht modifiziert und ein "_s"-Suffix an den Namen
gehängt. Was die bei printf gemacht haben weiß ich nicht, und ist
mir auch egal.

Gruß,
Michael Karcher

0 new messages