Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Autor : Tiago Portela
- Email : sapitando@gmail.com
- Sobre : Compilado com LCC-Win32 32bit . 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 = %Lf\n", (void*)(&format + 3), *(long double*)(&format + 3));
- printf("%p = %lf\n", (void*)(&format + 6), *(double*)(&format + 6));
- printf("%p = %u\n", (void*)(&format + 8), *(int*)(&format + 8));
- printf("%p = %p = %u\n", (void*)(&format + 9), *(void**)(&format + 9), **(int**)(&format + 9) );
- printf("\n\n");
- printf("%p = %u\n", (void*)((void**)args + 7), *(unsigned int*)(args + 7 * sizeof(uintptr_t)));
- printf("%p = %p = %u\n", (void*)((void**)args + 8), *((void**)args + 8), **((unsigned int**)args + 8));
- 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 %Lf %lf %u %p", "BBBBBBBBBB", "CCCCCCCCCC", ldCount, lfCount, uiCount, &uiCount);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement