The example you are using will only work in Borland/Embarcadero compilers, something the author of that book should have clarified for you. This pragma will not work with MCVS, gcc and clang compilers.
For gcc-like compilers, you can use this compiler extension instead:
void f1 (void);
void __attribute__((constructor)) f1 (void)
{
puts("Hello world");
}
Regarding Let us C, it turns out you are reading a harmful book written by an incompetent author. From SO's C book recommendation list:
Also do not use the book Let Us C (16th Edition, 2017) by Yashwant Kanetkar. Many people view it as an outdated book that teaches Turbo C and has lots of obsolete, misleading and incorrect material. For example, page 137 discusses the expected output from printf("%d %d %d\n", a, ++a, a++)
and does not categorize it as undefined behaviour as it should. It also consistently promotes unportable and buggy coding practices, such as using gets
, %[\n]s
in scanf
, storing return value of getchar
in a variable of type char
or using fflush
on stdin
.
This book has been read and reviewed by at least two well-known and respected C gurus on this site and the claims above show that this book is not just outdated - it is spectacularly bad. Counting yours sincerely as well, there's now at least three 100k+ rep C tag users of SO giving a big fat anti-recommendation against this book.
You need to stop reading this harmful book immediately. Please show this post to your teacher.