OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 15, 2021 12:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Solved]Is there a way for GCC to ignore invalid directives?
PostPosted: Mon Nov 02, 2020 4:15 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 167
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?


Last edited by pvc on Mon Nov 02, 2020 5:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Is there a way for GCC to ignore invalid directives?
PostPosted: Mon Nov 02, 2020 4:27 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7506
Location: Germany
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.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Is there a way for GCC to ignore invalid directives?
PostPosted: Mon Nov 02, 2020 5:51 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 167
It turns out GCC can accept input from stdin. So I just remove offending line with sed. No need for temporary files or anything.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group