Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- testing C inline
- -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O3
- */
- //main.c
- //---------
- #include <stdio.h>
- #include <stdlib.h>
- #include "dar1.h"
- #include "dar2.h"
- int main (int argc, char **argv)
- {
- float fV = 0.0f;
- int iCount = 0;
- printf("Enter float number: ");
- iCount = scanf("%f", &fV);
- if(iCount!=1||iCount==EOF)
- {
- printf("error occurred\n");
- return 1;
- }
- printf("Test 1: %f\n",testas1(1.0f,fV));
- printf("Test 2: %f\n",testas2(1.0f,fV));
- return 0;
- }
- //drc.h
- //---------
- #ifndef DRC_H
- #define DRC_H
- inline float tstPlus(float a)
- {
- return a+1.0f;
- }
- #endif
- dar1.c
- ----------
- #include <stdio.h>
- #include <stdlib.h>
- #include "dar1.h"
- #include "drc.h"
- inline float tstPlus(float);
- float testas1(float a,float b)
- {
- b = tstPlus(b);
- return a+b;
- }
- //dar2.c
- //----------
- #include <stdio.h>
- #include <stdlib.h>
- #include "dar2.h"
- #include "drc.h"
- inline float tstPlus(float);
- float testas2(float a,float b)
- {
- b = tstPlus(b);
- return a-b;
- }
- //dar1.h
- //----------
- #ifndef DAR1_H
- #define DAR1_H
- float testas1(float,float);
- #endif
- //dar2.h
- //----------
- #ifndef DAR2_H
- #define DAR2_H
- float testas2(float, float);
- #endif
- //drc.h without inline
- //=====================
- #ifndef DRC_H
- #define DRC_H
- float tstPlus(float a);
- #endif
- //drc.c without inline
- //=====================
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include "drc.h"
- float tstPlus(float a)
- {
- return a+1.0f;
- }
- //dar1.c without inline
- //======================
- #include <stdio.h>
- #include <stdlib.h>
- #include "dar1.h"
- #include "drc.h"
- float testas1(float a,float b)
- {
- b = tstPlus(b);
- return a+b;
- }
- /*
- *───────────────────*
- * asm without inline *
- *───────────────────*
- sym.testas1 ();
- sub rsp, 0x18
- movss dword [local_ch], xmm0
- movaps xmm0, xmm1
- call sym.tstPlus
- addss xmm0, dword [local_ch]
- add rsp, 0x18
- ret
- sym.testas2 ();
- sub rsp, 0x18
- movss dword [local_ch], xmm0
- movaps xmm0, xmm1
- call sym.tstPlus
- movss xmm2, dword [local_ch] ; [0xc:4]=0
- add rsp, 0x18
- subss xmm2, xmm0
- movaps xmm0, xmm2
- ret
- sym.tstPlus ();
- addss xmm0, dword [0x00000944]
- ret
- *───────────────────*
- * asm with inline *
- *───────────────────*
- sym.testas1 ();
- addss xmm1, dword [0x00000904]
- addss xmm0, xmm1 ;
- ret
- sym.testas2 ();
- addss xmm1, dword [0x00000904]
- subss xmm0, xmm1
- ret
- */
Advertisement
Add Comment
Please, Sign In to add comment