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

331
Visualizações
How can I count the number of bytes passed to a va_list function using format

For an example, I have a function foo()

int foo(const char* format,...) {
   va_list args;
   va_start(args, format)
   ...
   va_end(args);
   return bytes;
}

I have a format "%d%lf%s" and some arguments int a, double b and char* c is null-terminated string. How to pull variables from args and calculate sizeof(a)+sizeof(b)+sizeof(c)?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You cannot tell how many bytes were passed in the call, whatever that might mean. (Some arguments can be passed in registers. Some arguments might have padding between them.)

You can compute the sum of the sizeof the expected arguments, but it's tedious. You need to parse the format string; every time you find a format specifier, you add the size of the expected corresponding argument. Make sure you take length modifiers into account; %llu corresponds to sizeof(long long int), for example. However, %hu corresponds to an unsigned short which has been converted to an unsigned int; whether you want to count that as sizeof(short) or sizeof(int) might depend on what you plan to do with the answer.

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