Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail compile on purpose - Using source code of ongoing project

I am using the sources of project that is in an ongoing development and constantly changes.

In a specific scenario, I must change the sources of the project to adapt it to my own needs.

I want to create a define (or set of defines) that will ensure that if I updated the sources of the external project, and I didn't added my changes again to the new version of the code, I will fail the compile. In other words - I want to protect my self from forgetting writing certain code

How would you recommend?

Using IAR workbench, compiling for TI25XX

like image 426
Yoav R. Avatar asked Mar 20 '23 00:03

Yoav R.


2 Answers

You can use the preprocessor directives #ifndef and #error:

#ifndef SOMETHING
  #error "Error message!"
#endif

If SOMETHING is not defined, the compilation will halt and "Error message!" will be displayed.

What SOMETHING actually is will have to be decided by you. Perhaps it can be a version number1.

#if(CURRENT_VERSION < MINIMUM_VERSION)
  #error "Version out of date!"
#endif

1 Suggested by indiv.

like image 192
Fiddling Bits Avatar answered Apr 06 '23 10:04

Fiddling Bits


I'd suggest you add a Preprocessor Error Directive, #error, inside a #ifndef block. For example:

#ifndef YOAVS_SPECIAL_CODE
#error "You forgot the code Yoav."
#endif
like image 41
TRKemp Avatar answered Apr 06 '23 10:04

TRKemp