flat assembler
Message board for the users of flat assembler.
Index
> Windows > newline in printf, why \r\n not func as expect? |
Author |
|
revolution 11 Aug 2009, 22:51
Because fasm is not a C compiler! fasm does not "look into" the strings and convert \r things to 0x13 like C does.
|
|||
11 Aug 2009, 22:51 |
|
Borsuc 12 Aug 2009, 00:30
Why not define the string manually? You will have much more control over it that way
e.g: Code: string db 'a = %s ',13,10,' b = %s' cinvoke printf,string, 'apple', 'boy' _________________ Previously known as The_Grey_Beast |
|||
12 Aug 2009, 00:30 |
|
LocoDelAssembly 12 Aug 2009, 01:12
Also:
Code: cinvoke printf, <'a = %s', 13, 10, 'b = %s'>, 'apple', 'boy' But note that printf will expand 10 (\n) into CRLF when used on Windows so you don't need to do it explicitly and better you don't do it that way so you can reuse the code in Linux without any trouble. |
|||
12 Aug 2009, 01:12 |
|
sleepsleep 12 Aug 2009, 10:01
Quote:
i know fasm is not c compiler. but isn't it the convert task should be done by that particular "function printf()" instead of compiler? i mean, it is that function job to detects "\n" in the string pointer and do the CRLF itself.. assembler/compiler just pass the string pointer to this function, so.. i don't quite get it when you said compiler does the conversion. |
|||
12 Aug 2009, 10:01 |
|
revolution 12 Aug 2009, 10:06
A C compiler converts the backslash (\) escape codes at compile time.
printf converts the percent (%) escape codes at runtime. |
|||
12 Aug 2009, 10:06 |
|
sleepsleep 12 Aug 2009, 16:22
ok, i think i get it.
but somehow i found it weird, why c compiler doesn't let printf handles backslash (\) at runtime. is there any specific reason or it just ... tradition? |
|||
12 Aug 2009, 16:22 |
|
vid 12 Aug 2009, 16:59
Quote: is there any specific reason or it just ... tradition? Why should it be handled at runtime, if it can be handled once during compilation? You don't handle at runtime some thing whose result is same on every run. That is wasting of time. |
|||
12 Aug 2009, 16:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.