Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Calling an undefined function will have that behavior at link time: landmine.c: #ifndef CONSTANT #define CONSTANT 0 #endif #define assert_not_in_binary_if(e) do \ { \ if (e) \ undefi...
Answer
#11: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
#define assert_not_present_in_binary_if(e) do \- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
assert_not_present_in_binary_if(!CONSTANT);- }
- static void foo1(void)
- {
assert_not_present_in_binary_if(!CONSTANT);- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the assertion, and it is `foo0()` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time assertion, but link-time is good enough.
*EDITED: renamed `landmine()` to `assert_not_present_in_binary_if()`, per Dirk's suggestion.*
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- #define assert_not_in_binary_if(e) do \
- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
- assert_not_in_binary_if(!CONSTANT);
- }
- static void foo1(void)
- {
- assert_not_in_binary_if(!CONSTANT);
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the assertion, and it is `foo0()` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time assertion, but link-time is good enough.
- *EDITED: renamed `landmine()` to `assert_not_in_binary_if()`, per Dirk's suggestion.*
#10: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
#define landmine(e) do \- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
landmine(!CONSTANT);- }
- static void foo1(void)
- {
landmine(!CONSTANT);- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo0` as expected, and only when `CONSTANT == 0`.It would be nicer to have a compile-time landmine, but link-time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- #define assert_not_present_in_binary_if(e) do \
- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
- assert_not_present_in_binary_if(!CONSTANT);
- }
- static void foo1(void)
- {
- assert_not_present_in_binary_if(!CONSTANT);
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the assertion, and it is `foo0()` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time assertion, but link-time is good enough.
- *EDITED: renamed `landmine()` to `assert_not_present_in_binary_if()`, per Dirk's suggestion.*
#9: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- #define landmine(e) do \
- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
- landmine(!CONSTANT);
- }
- static void foo1(void)
- {
- landmine(!CONSTANT);
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.- It would be nicer to have a compile-time landmine, but link-time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- #define landmine(e) do \
- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
- landmine(!CONSTANT);
- }
- static void foo1(void)
- {
- landmine(!CONSTANT);
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo0` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time landmine, but link-time is good enough.
#7: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
intmain(void)- {
if (CONSTANT)foo1();elsefoo0();- }
static voidfoo0(void)- {
if (!CONSTANT)undefined_function();- }
static voidfoo1(void)- {
if (!CONSTANT)undefined_function();- }
- ```
<pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c/usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
<font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time landmine, but link-time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- #define landmine(e) do \
- { \
- if (e) \
- undefined_function(); \
- } while (0)
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int main(void)
- {
- CONSTANT ? foo1() : foo0();
- }
- static void foo0(void)
- {
- landmine(!CONSTANT);
- }
- static void foo1(void)
- {
- landmine(!CONSTANT);
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccmIFcBz.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time landmine, but link-time is good enough.
#6: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.
It would be nicer to have a compile-time landmine, but link time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time landmine, but link-time is good enough.
#5: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>
- It would be nicer to have a compile-time landmine, but link time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>
- I used `[[gnu::noipa]]` just to check which function is triggering the landmine, and it is `foo(0)` as expected, and only when `CONSTANT == 0`.
- It would be nicer to have a compile-time landmine, but link time is good enough.
#4: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #define CONSTANT 0
- void undefined_function(void);
static void foo0(void);static void foo1(void);- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
<pre>$ cc -Wall -Wextra -O3 landmine.c/usr/bin/ld: /tmp/ccH3ypC6.o: in function `main':landmine.c:(.text.startup+0x5): undefined reference to `undefined_function'- collect2: error: ld returned 1 exit status
</pre><pre>$ clang -flto -Weverything -O3 landmine.c/usr/bin/ld: /tmp/lto-llvm-50c0c6.o: in function `main':ld-temp.o:(.text.main+0x2): undefined reference to `undefined_function'clang: <font color="#FF5555"><b>error: </b></font><b>linker command failed with exit code 1 (use -v to see invocation)</b></pre>- It would be nicer to have a compile-time landmine, but link time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #ifndef CONSTANT
- #define CONSTANT 0
- #endif
- void undefined_function(void);
- [[gnu::noipa]] static void foo0(void);
- [[gnu::noipa]] static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre><font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=0 landmine.c
- /usr/bin/ld: /tmp/ccKhd1cW.o: in function `foo0':
- landmine.c:(.text+0x1): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- <font color="#55FF55"><b>alx@asus5775</b></font>:<font color="#5555FF"><b>~/tmp</b></font>$ cc -Wall -Wextra -O3 -DCONSTANT=1 landmine.c </pre>
- It would be nicer to have a compile-time landmine, but link time is good enough.
#3: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #define CONSTANT 0
- void undefined_function(void);
- static void foo0(void);
- static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre>$ cc -Wall -Wextra -O3 landmine.c
- /usr/bin/ld: /tmp/ccH3ypC6.o: in function `main':
- landmine.c:(.text.startup+0x5): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
$ clang -flto -Weverything -O3 landmine.c/usr/bin/ld: /tmp/lto-llvm-50c0c6.o: in function `main':ld-temp.o:(.text.main+0x2): undefined reference to `undefined_function'clang: error: linker command failed with exit code 1 (use -v to see invocation)- It would be nicer to have a compile-time landmine, but link time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #define CONSTANT 0
- void undefined_function(void);
- static void foo0(void);
- static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre>$ cc -Wall -Wextra -O3 landmine.c
- /usr/bin/ld: /tmp/ccH3ypC6.o: in function `main':
- landmine.c:(.text.startup+0x5): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- <pre>$ clang -flto -Weverything -O3 landmine.c
- /usr/bin/ld: /tmp/lto-llvm-50c0c6.o: in function `main':
- ld-temp.o:(.text.main+0x2): undefined reference to `undefined_function'
- clang: <font color="#FF5555"><b>error: </b></font><b>linker command failed with exit code 1 (use -v to see invocation)</b></pre>
- It would be nicer to have a compile-time landmine, but link time is good enough.
#2: Post edited
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #define CONSTANT 0
- void undefined_function(void);
static void foo(void);- int
- main(void)
- {
- if (CONSTANT)
foo();- else
foo();- }
- static void
foo(void)- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
<pre>$ clang -Weverything landmine.c/usr/bin/ld: /tmp/landmine-e06cf8.o: in function `foo':landmine.c:(.text+0x15): undefined reference to `undefined_function'clang: <font color="#FF5555"><b>error: </b></font><b>linker command failed with exit code 1 (use -v to see invocation)</b>- </pre>
<pre>$ cc -Wall -Wextra landmine.c/usr/bin/ld: /tmp/ccfoyrdJ.o: in function `foo':landmine.c:(.text+0x15): undefined reference to `undefined_function'collect2: error: ld returned 1 exit status</pre>- It would be nicer to have a compile-time landmine, but link time is good enough.
- Calling an undefined function will have that behavior at link time:
- `landmine.c`:
- ```c
- #define CONSTANT 0
- void undefined_function(void);
- static void foo0(void);
- static void foo1(void);
- int
- main(void)
- {
- if (CONSTANT)
- foo1();
- else
- foo0();
- }
- static void
- foo0(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- static void
- foo1(void)
- {
- if (!CONSTANT)
- undefined_function();
- }
- ```
- <pre>$ cc -Wall -Wextra -O3 landmine.c
- /usr/bin/ld: /tmp/ccH3ypC6.o: in function `main':
- landmine.c:(.text.startup+0x5): undefined reference to `undefined_function'
- collect2: error: ld returned 1 exit status
- </pre>
- $ clang -flto -Weverything -O3 landmine.c
- /usr/bin/ld: /tmp/lto-llvm-50c0c6.o: in function `main':
- ld-temp.o:(.text.main+0x2): undefined reference to `undefined_function'
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- It would be nicer to have a compile-time landmine, but link time is good enough.
#1: Initial revision
Calling an undefined function will have that behavior at link time: `landmine.c`: ```c #define CONSTANT 0 void undefined_function(void); static void foo(void); int main(void) { if (CONSTANT) foo(); else foo(); } static void foo(void) { if (!CONSTANT) undefined_function(); } ``` <pre>$ clang -Weverything landmine.c /usr/bin/ld: /tmp/landmine-e06cf8.o: in function `foo': landmine.c:(.text+0x15): undefined reference to `undefined_function' clang: <font color="#FF5555"><b>error: </b></font><b>linker command failed with exit code 1 (use -v to see invocation)</b> </pre> <pre>$ cc -Wall -Wextra landmine.c /usr/bin/ld: /tmp/ccfoyrdJ.o: in function `foo': landmine.c:(.text+0x15): undefined reference to `undefined_function' collect2: error: ld returned 1 exit status</pre> It would be nicer to have a compile-time landmine, but link time is good enough.