sponsor Vim development Vim logo Vim Book Ad

AddIfndefGuard : Add the #ifndef/#define/#endif guard to a C/C++ header file

 script karma  Rating 21/18, Downloaded by 992  Comments, bugs, improvements  Vim wiki

created by
Rory McCann
 
script type
utility
 
description
When one writes a header file for C/C++, compile errors will occur if the same header script is included more than once. A common solution is to add
     #ifndef FILENAME_H
     #define FILENAME_H
to the start of a file, and
     #endif
to the end. This solves the problem.

However this is mechanical and routine. So the computer should do it. So here's a script to do it.

It will add those lines to the top of the file you call it in. It will change FILENAME to be the uppercase name of that file, ommiting the file extension. It will not (yet) check to see if a #define/#ifndef/#endif black has already been added. It will not check the filename, so it can be called on anyfile.
 
install details
Unzip the file. Read the README (if you want). Place AddIfndefGuard.vim to the plugins directory. (On UNIX it's ~/.vim/plugins/)
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
AddIfndefGuard.zip 0.1 2005-02-22 6.0 Rory McCann Initial upload
ip used for rating: 18.216.251.37

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github