Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

386
Visualizações
Is this a valid definition for main()

The C11 Standard declares that:

5.1.2.2.1 Program startup

  1. The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

    int main(void) { /* ... */ }
    

    or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

    int main(int argc, char *argv[]) { /* ... */ }
    

    or equivalent; 10), or in some other implementation-defined manner.


10) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on.

We will ignore this part: or in some other implementation-defined manner. since I'm interested only in definitions equivalent to the two above examples.

Would this be a valid definition for main since char* a[4] and char** are equivalent:

int main(int argc, char* argv[4]){/*...*/}

How about a VLA array, we are assuming printf will return a positive int value:

int main(int argc, char* argv[printf("Hello there!")]){/*...*/}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Yes, this is all covered by the "or equivalent". The footnote about renaming parameters or using typedefed types are just examples.

My favorite variant is

int main(int argc, char* argv[argc+1]){/*...*/}

because it has the most information about the semantic of all main functions.

over 4 years ago · Santiago Trujillo Relatório

0

int main(int argc, char* argv[4]){/*...*/}  

is a valid signature of main. Compiler will ignore 4 in char argv[4] and it is equivalent to char argv[] = char **argv. Same goes with second signature.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda