Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External includes repeatedly included #16

Open
lwalewski opened this issue Aug 25, 2015 · 0 comments
Open

External includes repeatedly included #16

lwalewski opened this issue Aug 25, 2015 · 0 comments

Comments

@lwalewski
Copy link

According to the IncludeFile() definition the built-in include headers (such as stdio.h) are protected against multiple inclusion, so the following code runs with no problems:

void main(void) {
  while (1) {
#include <stdio.h>
  }
}

I agree it does not make sense in itself, but read on to see why I need it. As per PicocPlatformScanFile() such a protection is not implemented for user-defined includes, so the following code will sooner or later explode in memory when interpreted by PicoC:

void main(void) {
  while (1) {
#include "my-include.h"
  }
}

with my-include.h containing arbitrary (but valid) C code, e. g.:

int i;

At the same time the same source compiled with gcc runs at constant memory. I would be grateful for explanation, what is the logic behind? What use case could take advantage of multiple inclusions of the same file?

For my usage scenario such a design is lethal, since I am trying to parametrize the program's behaviour by defining the body of a function in a separate file, which could be modified by the user, e. g.:

void my_func(void) {
#include "my-include.c"
}

The function itself would contain assignments and logical operations on input variables that modify output variables and would be called in a loop by the main program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant