Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 11336

Funções static

$
0
0
certo ... estás a dizer que este exemplo não acontece no teu computador: static.h #pragma once static int func(void) { return 10; } foo.h #pragma once int foo(void); bar.h #pragma once int bar(void); foo.c #include "static.h" #include "foo.h" #include <stdio.h> int foo(void) { return printf("foo : %d\n", func()); } bar.c #include "static.h" #include "bar.h" #include <stdio.h> int bar(void) { return printf("bar : %d\n", func()); } shell: $ objdump -t ./obj/src/bar.o ./obj/src/bar.o: file format pe-x86-64 SYMBOL TABLE: [ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000000000000000 bar.c File [ 2](sec 1)(fl 0x00)(ty 20)(scl 3) (nx 1) 0x0000000000000000 func <---------------------------------- AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0 [ 4](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000000000000000b bar [ 5](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .text AUX scnlen 0x2c nreloc 2 nlnno 0 [ 7](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .data AUX scnlen 0x0 nreloc 0 nlnno 0 [ 9](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .bss AUX scnlen 0x0 nreloc 0 nlnno 0 [ 11](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .xdata AUX scnlen 0x14 nreloc 0 nlnno 0 [ 13](sec 5)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .pdata AUX scnlen 0x18 nreloc 6 nlnno 0 [ 15](sec 6)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .rdata AUX scnlen 0xa nreloc 0 nlnno 0 [ 17](sec 7)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_info AUX scnlen 0x16f nreloc 5 nlnno 0 [ 19](sec 8)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_abbrev AUX scnlen 0x51 nreloc 0 nlnno 0 [ 21](sec 9)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_aranges AUX scnlen 0x30 nreloc 2 nlnno 0 [ 23](sec 10)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_line AUX scnlen 0x59 nreloc 1 nlnno 0 [ 25](sec 12)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .rdata$zzz AUX scnlen 0x11 nreloc 0 nlnno 0 [ 27](sec 13)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_frame AUX scnlen 0x68 nreloc 4 nlnno 0 [ 29](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 printf $ objdump -t ./obj/src/foo.o ./obj/src/foo.o: file format pe-x86-64 SYMBOL TABLE: [ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000000000000000 foo.c File [ 2](sec 1)(fl 0x00)(ty 20)(scl 3) (nx 1) 0x0000000000000000 func <------------------------------------------------------ AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0 [ 4](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000000000000000b foo [ 5](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .text AUX scnlen 0x2c nreloc 2 nlnno 0 [ 7](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .data AUX scnlen 0x0 nreloc 0 nlnno 0 [ 9](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .bss AUX scnlen 0x0 nreloc 0 nlnno 0 [ 11](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .xdata AUX scnlen 0x14 nreloc 0 nlnno 0 [ 13](sec 5)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .pdata AUX scnlen 0x18 nreloc 6 nlnno 0 [ 15](sec 6)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .rdata AUX scnlen 0xa nreloc 0 nlnno 0 [ 17](sec 7)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_info AUX scnlen 0x16f nreloc 5 nlnno 0 [ 19](sec 8)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_abbrev AUX scnlen 0x51 nreloc 0 nlnno 0 [ 21](sec 9)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_aranges AUX scnlen 0x30 nreloc 2 nlnno 0 [ 23](sec 10)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_line AUX scnlen 0x59 nreloc 1 nlnno 0 [ 25](sec 12)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .rdata$zzz AUX scnlen 0x11 nreloc 0 nlnno 0 [ 27](sec 13)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x0000000000000000 .debug_frame AUX scnlen 0x68 nreloc 4 nlnno 0 [ 29](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 printf o exemplo é optimo : apresenta algo que a linguagem deixa fazer, deixando uma porta escancarada para problemas sérios. os teus exemplos ficam a saber a pouco quando a sua utilização é obrigatória para resolução de certos problemas. a multipla heranla foi demonstrado por outras linguagem que é dispensável.

Viewing all articles
Browse latest Browse all 11336

Trending Articles