sogo
sogo

Reputation: 351

about segmentation fault in LINUX

I am doing a homework developing SIC/XE assembler in LINUX.

When I made a code, I confronted some error, but I do not know why this is happen. Would you explain for me why this problem occurred?

The code shows below reveals 'test.asm' file with token.

178             printf("token1: %s \t",token1);
179             printf("token2: %s \t",token2);
180             printf("token3: %s \t",token3);
181             printf("token4: %s \t",token4);
182             printf("ss\nss");

According to this, especially "ss\nss" statement, I expected printed out result like below.

    sstoken1: LDT   token2: LENGTH  token3: (null)  token4: (null)  ss
    sstoken1: WLOOP         token2: TD      token3: OUTPUT  token4: (null)  ss
    ss

However, when I run this program till the end, I met segmentation fault and met weird situation.

sstoken1: OUTPUT        token2: BYTE    token3: X'05'   token4: (null)  ss
sstoken1: END   token2: FIRST   token3: (null)  token4: (null)  ss
Segmentation fault.

There is no 'ss' before the 'Segmentation fault' statement. I can not figure why. Would you explain it for me please?

Upvotes: 2

Views: 247

Answers (1)

kofemann
kofemann

Reputation: 4413

I believe it's printed, by process killed by SEGV before stdout is flushed. Try to add:

fflush(stdout);

after printf statement.

Upvotes: 1

Related Questions