Macros are just text replacement, so they can expand to just about anything you want. In this case, the macro is being used to expand into two arguments to a function. The function expects a string and the number of characters in the string as arguments, and the SNS()
macro generates them. So
ft_display_fatal(SNS("File name missing.\n"), 2, 1)
expands into
ft_display_fatal(("File name missing.\n"),(sizeof("File name missing.\n")-1), 2, 1)
This is basically only useful when the parameter is a string literal: sizeof("string")
is the size of the char
array including the trailing null byte, and -1
subtracts that byte to get the number of significant characters in the string. This is the len
argument to the ft_display_fatal
function (I'm not sure why it can't just use strlen()
to get this by itself -- I guess it's a performance optimization).