Comments (8)
Here's a perl script to make that change:
change_header.pl
#!/usr/bin/perl
open INFILE, "<$ARGV[0]" or die "Unable to open <$ARGV[0]: $!\n";
@lines = <INFILE>;
close (INFILE);
$header_name = uc($ARGV[0]);
$header_name =~ s/\./\_/g;
@output = ();
$pragma_flag = 0;
foreach $line(@lines) {
if ($line =~ m/\#pragma\s+once/gi) {
push @output, "#ifndef $header_name\n";
push @output, "#define $header_name\n";
$pragma_flag = 1;
}
else {
push @output, $line;
}
}
if ($pragma_flag == 1){
push @output, "#endif\n";
}
open OUTFILE, ">$ARGV[0]" or die "Unable to open >$ARGV[0]: $!\n";
foreach $line(@output) {
print OUTFILE $line;
}
close (OUTFILE);
This is how the script works. Note that it overwrites the file.
$ cat header.h
#pragma once
Line 1
Line 2
Line 3
$ ./change_header.pl header.h
$ cat header.h
#ifndef HEADER_H
#define HEADER_H
Line 1
Line 2
Line 3
#endif
And this is how you run it on all your files.. Make a backup first though, and do a test run with a dummy file to make sure everything works as expected!!
find . -name \*.h -exec ./change_header.pl {} \;
from linter-gcc.
Hello. Has your issue been resolved?
from linter-gcc.
Well technically yes, the script works, but why does gcc warn me about using pragma once?
from linter-gcc.
The reason is that although #pragma once
is widely supported, it is still a non-standard feature. You can read more about this here. What I do in these scenarios is switch to a standard feature to remove the warning. I think it's a good idea to favour a clean build (one with no warnings, even with all warning options switched on) as it helps you to identify problems easily. However, the choice is entirely yours.
from linter-gcc.
Ah thank you very much, I actually didn't know that. I don't know why it would be non-standard, as it is much more practical than the default include guards... Whatever.
from linter-gcc.
Sorry for the bump, but saying that #pragma once
is a non-standard feature is irrevelant to the warning, @hebaishi. The warning is because gcc is seeing one file being passed to it, the header file with the #pragma once
in it, and it 'thinks': "Hey, this is a main file, why does it have a pragma that tells me not to include it more than once? I'll let the developer know about this."
This warning is a problem with how the linter works, it passes the file you are working on as the main file to gcc. In this case, I would reccomend passing the flag to disable the #pragma once
warning to gcc, -Wno-
... wait a moment, this flag doesn't exist.
I'd recomend re-opening this issue, or perhaps I can open a new issue that references this one.
My thoughts for fixing this -- you could create a file that includes the header file you're trying to lint, or you could match on that warning and remove it. I'd recomend the former, though the latter might be useful as a configuration option so that users can remove warnings that they can't disable.
Example commands for the former:
gcc -c -fsyntax-only myheader.h
as opposed to:
echo '#include "myheader.h"' | gcc -x c++-header -c -fsyntax-only -
from linter-gcc.
@KitLing thanks for the useful info. I think the second option would be better: it avoids the creation of a temporary file, and adds flexibility so that the user can potentially remove other warnings (if there are any) that can't be disabled.
from linter-gcc.
Well, piping the #include to gcc avoids the temporary file, which is why I provided a (shell) example demonstrating that.
I do agree that the second option would give extra flexibility, but it could also encourage people to block specific warnings that do have flags to disable them. And, honestly, I'd prefer the first method because it's better to just plain not generate the spurious warning than to filter it out.
Doesn't mean we can't have both, just would reccomend warnings around the second option.
from linter-gcc.
Related Issues (20)
- Linter isn't showing issues (c/c++) HOT 2
- it stops working since the 1.34.0 atom update HOT 2
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 2
- linter-gcc doesn't work HOT 4
- consider this project dead if this issue is not removed (latest commit was on 2017 jan) HOT 3
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 2
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 2
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 1
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 1
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 1
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 1
- Uncaught TypeError: _this.notificationEl.querySelector is not a function HOT 1
- Object.dirname is deprecated.
- Uncaught TypeError: Cannot read property 'binary' of undefined
- Relative paths are relative to Atom's $PWD, not the project root
- string variables not highlighted
- Colors in the linter panel
- I cant install atom linter gcc.its shows"npm WARN deprecated [email protected]: No longer maintained - Use lodash probably npm ERR! Unexpected end of JSON input while parsing near '...MGZNbL9YcGBJl4MH4nrxH' npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\stark siv\.atom\.apm\_logs\2020-12-26T17_25_37_936Z-debug.log" A little help is appreciated,♥ HOT 2
- Just want my GCH address for open sea? HOT 1
- Cannot find module 'tempfile'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linter-gcc.