OSDev.org
https://forum.osdev.org/

[Solved]Is there a way for GCC to ignore invalid directives?
https://forum.osdev.org/viewtopic.php?f=13&t=37418
Page 1 of 1

Author:  pvc [ Mon Nov 02, 2020 4:15 am ]
Post subject:  [Solved]Is there a way for GCC to ignore invalid directives?

Hi, I want GCC NOT to error out on invalid directive.
I need some C code to be runnable from command line as scripts. I am using TCC's (Tiny C Compiler) -run option, which allows to do just that. To simplify some Shell scripts (some of these C scripts need special invocation) I am using interpreter line inside the script. Something like:
Code:
#!/usr/bin/tcc -run

#include <stdio.h>

int main()
{
    printf("Trolololo!\n");
    return 0;
}


The problem is that it's difficult to debug code started this way. From time to time I need to properly compile and run such script with GCC and debug with GDB. But whenever GCC encounters first line, it errors out, complaining about invalid directive. For now I just comment out first line whenever I am using GCC, but sometimes I forget to uncomment it before commiting the code to repository and this causes some breakage in my Shell scripts. Is there some way to tell GCC to ignore first line or invalid directives?

Author:  Solar [ Mon Nov 02, 2020 4:27 am ]
Post subject:  Re: Is there a way for GCC to ignore invalid directives?

Not to my knowledge. And IMHO it would be the wrong way to solve this problem.

You talk about "forgetting to uncomment before comitting". That is where I would catch this kind of error: By means of a pre-commit check. All modern version control systems allow this kind of thing. Write a script that checks the first line for a commented-out interpreter directive, and have it reject the commit with a helpful error message.

Author:  pvc [ Mon Nov 02, 2020 5:51 am ]
Post subject:  Re: Is there a way for GCC to ignore invalid directives?

It turns out GCC can accept input from stdin. So I just remove offending line with sed. No need for temporary files or anything.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/