Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

     Posts tagged "c_cplusplus"

Notes on C++ development with Emacs on Ubuntu Linux

Here are my notes on setting up an Emacs C++ development environment. I'm using GNU g++ (4.3.3), GNU make (3.81), GNU gdb (3.8-debian), and GNU emacs (23.0.92.1 built from CVS 2009-04-22) on Ubuntu Linux (9.04 Jaunty Jackalope).

Install tools

If you don't already have g++, make, and gdb, install them:

sudo apt-get install g++ make gdb

Create files

  • Create a project directory:
    mkdir helloworld
  • Create a source file helloworld/hello.cpp:
    #include <iostream>
    
    int main(void) 
    {
       char greeting[] = "Hello World!";
       std::cout << greeting << std::endl;
       return 0;
    }
  • Create a makefile ...
... read more »

How to remove C style comments using Python

The Perl FAQ has an entry How do I use a regular expression to strip C style comments from a file? Since I've switched to Python, I've adapted the Perl solution to Python. This regular expression was created by Jeffrey Friedl and later modified by Fred Curtis. I'm not certain, but it appears to use the "unrolling the loop" technique described in Chapter 6 of Mastering Regular Expressions.

remove_comments.py:

import re
import sys

def remove_comments(text):
    """ remove c-style comments.
        text: blob of text with comments (can include newlines)
        returns: text with comments removed
    """
    pattern = r"""
                            ##  --------- COMMENT ...
... read more »
Created with Django | Hosted by Slicehost