Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Autor : Tiago Portela
- Email : sapitando@gmail.com
- Sobre : Compilado com TDM-GCC 5.10 64 bit. Tentando entender a disposição na memória dos argumentos da função variádica,
- cada compilador(e sua própria versão) implementa a sua maneira própria.
- Obs : Apenas tentando aprender algoritimos, sozinho, por hobby. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdarg.h>
- #include <conio.h>
- void Myprintf(const char* format,...)
- {
- va_list args;
- args = (va_list)(&format + 1); // va_start(args, format);
- void *p = (void*)args;
- printf("%p -> %p = %s\n", (void*)(&format), format, format);
- printf("%p -> %p = %s\n", (void*)(&format + 1), (void*)*(&format + 1), *(&format + 1));
- printf("%p -> %p = %s\n", (void*)(&format + 2), (void*)*(&format + 2), *(&format + 2));
- printf("%p -> %p = %lf\n", (void*)(&format + 3), (void*)*(&format + 3), (double)**(long double**)(&format + 3));
- printf("%p = %lf\n", (void*)(&format + 4), *(double*)(&format + 4));
- printf("%p = %i\n", (void*)(&format + 5), *(int*)(&format + 5));
- printf("%p = %p = %u\n", (void*)(&format + 6), *(void**)(&format + 6), **(int**)(&format + 6) );
- printf("\n\n");
- printf("%p = %u\n", (void*)((void**)args + 4), *(unsigned int*)(args + 4 * sizeof(uintptr_t)));
- printf("%p = %p = %u\n", (void*)((void**)args + 5), *((void**)args + 5), **((unsigned int**)args + 5));
- printf("\n\n");
- vfprintf(stdout, format, (va_list)p);
- va_end(args);
- printf("\n");
- }
- int main(void){
- long double ldCount = 99.50;
- double lfCount = 250.125;
- unsigned int uiCount = 199;
- Myprintf("AAAAAAAAAA %s %s %G %lf %u %p", "BBBBBBBBBB", "CCCCCCCCCC", ldCount, lfCount, uiCount, &uiCount);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement