Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Recommended Books



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2008/04/recommended-books/

You should be redirected in 2 seconds.



I love having a subscription to Safari Books Online. Currently my company provides a free subscription, but if I get a new job, I might consider subscribing myself. Since I get to browse a number of books at no cost, I thought I'd note which books are my favorites. (Note, I am not being paid by Safari Books Online.)


General Software
  • Structure and Interpretation of Computer Programs, Second Edition, Harold Abelson and Gerald Jay Sussman, MIT Press, ?year?
    I learned about this book through a job posting. It might bring you to tears if you get it. I'm only in the second chapter. It is used in an introductory Computer Science course at MIT. It uses Scheme (Lisp) to demonstrate concepts.
    Available free online at: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html
    A free video lecture series is also available.

C
  • The C Programming Language, Second Edition, Brian W. Kernighan and Dennis M. Ritchie, Prentice Hall, 1988
    The definitive C book.

Python
  • Core Python Programming, Second Edition, Wesley J. Chun, Prentice Hall, September 18, 2006
    Usually I like O'Reilly books best, but I slightly prefer Chun's text to Learning Python.
    Available at Safari Books Online

Django (Python)
  • The Django Book, Apress, December 2007
    I think this is the first official Django book.
    Available free online at: http://www.djangobook.com/

SQLite
  • The Definitive Guide to SQLite, Mike Owens, Apress, May 2006
    I browsed a few SQL books but liked this one better than most. It has a good theory section.
    Available at Apress.com

Linux or related
  • X Power Tools, Chris Tyler, O'Reilly, December 15, 2007
    Lots of good information on the X Window System and more; easy to understand. I wish the basic Ubuntu or Linux books had some of this information.
    Available at Safari Books Online

Ruby
[Read the full post...]

How to remove C style comments using Python



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/11/remove-c-comments-python/

You should be redirected in 2 seconds.



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.

I included two versions from the Perl FAQ. The simple version removes single-line or multi-line C-style comments from a file, but has the possibly unwanted behavior of removing text which looks like comments from within a quoted string. The advantage is that it uses a regular expression that is easier to understand.

The second version is more robust-- it handles comments within a quoted string properly (i.e. it does not remove them). This is the recommended version.



Simple version

The simple version uses a regular expression that is only 9 characters long. The key to the regular expression is the use of the lazy, or non-greedy, quantifier, *?. From Mastering Regular Expressiongs, Second Edition by Jeffrey E. F. Friedl:

Quantifiers are normally "greedy", and try to match as much as possible. Conversely, these non-greedy versions match as little as possible, just the bare minimum needed to satisfy the match.
Matching a C-style comment using such a simple pattern would not be possible without the use of lazy quantifiers because of the C-style comment's two character ending.



remove_comments_simple.py:
# remove_comments_simple.py
import re
import sys

# open file
filename = sys.argv[1]
code_with_comments = open(filename).read()

# strip comments
regex = re.compile(r"/\*.*?\*/", re.MULTILINE|re.DOTALL)
code_without_comments = regex.sub("", code_with_comments)

# write new file
fh = open(filename+".nocomments", "w")
fh.write(code_without_comments)
fh.close()

Example:
To test the script, I created a test file called testfile.c:
/* This is a C-style comment. */
This is not a comment.
/* This is another
 * C-style comment.
 */
"This is /* also not a comment */"

Run the script:
To use the script, I put my script, remove_comments_simple.py, and my test file, testfile.c, in the same directory and ran the following command:
python remove_comments_simple.py testfile.c

Results:
The script created a new file called testfile.c.nocomments:
This is not a comment.

"This is "


Robust version (Recommended)

From the Perl FAQ, this version was created by Jeffrey Friedl and later modified by Fred Curtis. I'm not certain, but this version appears to use the "unrolling the loop" technique described in Chapter 6 of Mastering Regular Expressions.


remove_comments.py:
# remove_comments.py
import re

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 ---------
           /\*              ##  Start of /* ... */ comment
           [^*]*\*+         ##  Non-* followed by 1-or-more *'s
           (                ##
             [^/*][^*]*\*+  ##
           )*               ##  0-or-more things which don't start with /
                            ##    but do end with '*'
           /                ##  End of /* ... */ comment
         |                  ##  -OR-  various things which aren't comments:
           (                ## 
                            ##  ------ " ... " STRING ------
             "              ##  Start of " ... " string
             (              ##
               \\.          ##  Escaped char
             |              ##  -OR-
               [^"\\]       ##  Non "\ characters
             )*             ##
             "              ##  End of " ... " string
           |                ##  -OR-
                            ##
                            ##  ------ ' ... ' STRING ------
             '              ##  Start of ' ... ' string
             (              ##
               \\.          ##  Escaped char
             |              ##  -OR-
               [^'\\]       ##  Non '\ characters
             )*             ##
             '              ##  End of ' ... ' string
           |                ##  -OR-
                            ##
                            ##  ------ ANYTHING ELSE -------
             .              ##  Anything other char
             [^/"'\\]*      ##  Chars which doesn't start a comment, string
           )                ##    or escape
    """
    regex = re.compile(pattern, re.VERBOSE|re.MULTILINE|re.DOTALL)
    noncomments = [m.group(2) for m in regex.finditer(text) if m.group(2)]

    return "".join(noncomments)

if __name__ == '__main__':
    filename = sys.argv[1]
    code_w_comments = open(filename).read()
    code_wo_comments = remove_comments(code_w_comments)
    fh = open(filename+".nocomments", "w")
    fh.write(code_wo_comments)
    fh.close()

Example:
To test this script, I used the same test file, testfile.c:
/* This is a C-style comment. */
This is not a comment.
/* This is another
 * C-style comment.
 */
"This is /* also not a comment */"

Run the script:
To use the script, I put the script, remove_comments.py, and my test file, testfile.c, in the same directory and ran the following command:
python remove_comments.py testfile.c

Results:
The script created a new file called testfile.c.nocomments:
This is not a comment.

"This is /* also not a comment */"



---------------
Minor note on Perl to Python migration:
I modified the original regular expression comments a little bit. In particular, I had to put at least one character after the ## Non "\ and ## Non '\ lines because, in Python, the backslash was escaping the following newline character and the closing parenthesis on the following line was being treated as a comment by the regular expression engine. This is the error I got, before the fix:
$ python remove_comments.py
Traceback (most recent call last):
  File "remove_comments.py", line 39, in <module>
    regex = re.compile(pattern, re.VERBOSE|re.MULTILINE|re.DOTALL)
  File "C:\Programs\Python25\lib\re.py", line 180, in compile
    return _compile(pattern, flags)
  File "C:\Programs\Python25\lib\re.py", line 233, in _compile
    raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis


[Read the full post...]

My software tools list



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/08/current-configuration/

You should be redirected in 2 seconds.



Below is a table of my current software configuration. If you notice a lot of "I switched from ..." statements, keep in mind that I am a programmer who likes shiny things.

Category Currently using Comments
Operating System Ubuntu 8.04, Windows XP, Windows Vista Work Desktop: Ubuntu Hardy via coLinux on Windows XP and Cygwin when needed.
Home Laptop: dual-boot Windows Vista with Cygwin and Ubuntu Hardy
Home Desktop: Ubuntu Hardy

I am in the process of migrating from Windows to Linux. My first Ubuntu install was in 2007 (dual-boot) and I got my first Windows-free machine in 2008. Currently I am using Cygwin and coLinux when on Windows. Cygwin integrates better with Windows applications, but coLinux is super fast and allows you to run a full Linux distro on top of Windows. Windows does have some advantages, but overall I prefer Linux.

I don't have enough experience with OSX to draw any authoritative conclusions, though I think Mark Pilgrim has biased me against Apple. Also, I think Linux's free as in beer (and somewhat related free as in speech) characteristics vs. Mac's expensive (and somewhat related proprietary) characteristics resonate with the cheap engineer in me.

Additional Linux vs. Mac commentary from some A-list geeks:
Window Manager wmii Dynamic, tiling, scriptable window manager that doesn't require a mouse. It sucks less.

I switched from ratpoison at the same time I started using coLinux because running native Linux allowed me to use any Linux window manager as well.

Recently, some have switched from wmii to xmonad, the new Haskell tiling window manager. It has some nice features over wmii, including dual head support, but after a brief excursion, I slightly prefer wmii's way of doing things.

If you're a hard core Lisper, stumpwm is the window manager for you. It has a REPL. This one seems a little too hard core for me, especially since I don't know Lisp (yet).

Other options: ion, dwm, awesomewm

Editor/IDE GNU Emacs Switched from Eclipse in 2007. It was a slow transition, but worth it. I think Emacs is definitely worth the investment if you do a lot of coding.

Terminal urxvt +
screen
urxvt supports xft (anti-aliased) fonts, real transparency (not that I actually use transparency with wmii), and fading (which I do use with wmii) and it is much lighter than gnome-terminal or konsole. screen allows me to switch terminal sessions without ugly tabs, attach to remote sessions, search through the scrollback buffer, and more.

Version Control System Mercurial Switched from Subversion in June 2007. The merging in Mercurial is very nice and can be done without thinking. I do miss Subversion/Subclipse's revision history viewer, file compare, and ability to isolate files apart from changesets.

Compiled Language C Wouldn't mind learning C++. Although, Linus doesn't like it.

Dynamic Language Python 2.5 My love for python is strong. I switched from Perl in 2005 and have no regrets. Object-oriented, easy to read (no more TIMTOWTDI), and smart people use it. I also want to learn Javascript 2 becuase it is the "Next Big Language" and Lisp because it is the "most powerful language".

On Python vs. Ruby: from what I've read, I characterize Ruby as the more expressive language more similar to Perl (than Python is) and Python as the more regimented language. Since I like regimented, I like Python.

On Python vs. Lisp: I've concluded that I lack the intelligence to harness enough of Lisp's power to counteract its non-practicality (e.g. lack of libraries).

Some other links:
Paul Graham: Python is getting closer to Lisp (2002)
Paul Prescod: no it isn't

Web Framework Django I haven't tried much else, but Django is pretty cool.

Here are some links:
Ian Bicking: There's so much more than Rails (2005), What PHP deployment gets right (2008)

Web Browser Conkeror Not to be confused with Konqueror, Conkeror is an emacs-like, keyboard driven, scriptable, Mozilla-based web browser. I've used it almost full time since January 2008. It is still considered alpha stage software so there are a number of bugs. However, it is still pretty sweet. I use Firefox as a backup (and IE Tab for Launchcast and Netflix on Windows). Unfortunately, one of the annoying things in Firefox 2 is present in Conkeror as well-- memory leaks. Based on this Mozilla article and some brief personal experience, Firefox 3 has made fixes in this area. It would be nice if Conkeror could benefit from the Firefox 3 fixes.

Email/PIM Undecided Thunderbird?, Evolution?, Mutt?, Gnus?, Alpine?, Gmail?, Claws Mail?,

I currently use Microsoft Outlook with an Exchange Server at work. Evolution supports Exchange Server through Outlook Web Access (OWA), but I couldn't get it to work for me. Thunderbird (and I assume others) support Exchange through IMAP, but this is only available at work by special request.

Links:
Adam Gomaa chooses Claws Mail over Thunderbird, Evolution, Mutt, and Gnus (2007)

PDF Viewer KPDF Preferred over Gnome's Evince
Screen Capture KSnapshot Courtesy of Mark Pilgrim's essentials list
Graphical diff/merge KDiff3 I started using KDiff a while ago on Windows and have always liked it. I'm thinking, though, since I'm an Emacs person, I ought to use Ediff.
Updated 7/2/2008
[Read the full post...]

Data hiding in C, an object-oriented technique



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/04/data-hiding-in-c-object-oriented/

You should be redirected in 2 seconds.



I am working on some legacy code which uses almost entirely global variables. My task is to change the scope of the variables that don't need to be global. I have changed many of the variables to function scope because they are not used elsewhere, however there is a lot of data that is shared among functions.

My first idea was to create data structures of the shared data and pass pointers to those structures through the parameter list of the functions. However I had some multi-layer function calls. I.e., function1 calls function2 which calls function3. Only the last function called needed the shared data, but the parameter needed to be passed among many functions.

After looking over some other code, I got the idea for using "get" and "set" functions as used in object-oriented programming to access the data structures. The data structures are defined as static at the file scope. The file is like an object with functions that operate on the static data. External (outside the file) access to the data is only allowed through external interface functions declared in a header file which get and set the data. Here is a simple example with an accessor "get" function which passes a pointer to the static structure. It is declared as a pointer to a pointer because I need to pass the pointer by reference so it can be modified. However the structure itself is declared const so that the accessor won't change the data by mistake. To summarize, it is a pointer to a const structure passed by reference.

main.c:
#include 
#include "algorithm.h"
        
int main(void)
{
   const ALGORITHM_DATA *alg_ptr;
      
   Algorithm();
   GetAlgorithmData(&alg_ptr);
   /*alg_ptr->data1 = 99.9;*/ /* This is illegal */
   printf("%f\n", alg_ptr->data1);
   printf("%f\n", alg_ptr->data2);
   printf("%f\n", alg_ptr->data3);
   
   return 0;
}
algorithm.c:
#include "algorithm.h"

static ALGORITHM_DATA alg;

void GetAlgorithmData(const ALGORITHM_DATA **out)
{
   *out = &alg;
}
 
void Algorithm(void)
{
   alg.data1 = 1.0;
   alg.data2 = 2.0;
   alg.data2 = 3.0;
}
algorithm.h:
#ifndef ALGORITHM_H_
#define ALGORITHM_H_

typedef struct {
   double data1;
   double data2;
   double data3;
} ALGORITHM_DATA;

void GetAlgorithmData(const ALGORITHM_DATA **out);
void Algorithm(void);

#endif /*ALGORITHM_H_*/

[Read the full post...]

How to share non-global C data structures



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/02/how-to-share-non-global-c-data/

You should be redirected in 2 seconds.



My goal is to share C data structures without using global variables. I have one function that will fill the data structure and other functions that will use and optionally modify the data. I would also like the data structure definition to be in the same file as the function that fills it. (It looks like this last requirement requires pointers to pointers and a malloc so I will abandon it. See this thread in the comp.lang.c newsgroup.)

My solution is to pass pointers to structures to functions as described here: http://irc.essex.ac.uk/www.iota-six.co.uk/c/h4_structs_part_3.asp Here is my implementation and notes:

main.c:
main.c contains the main function which calls the other functions that operate on the data structure. It also defines (allocates memory) for the data structure at the file level. The data structure is declared using the static keyword so that it will have static duration (i.e. it will exist from program start to finish), but it will have internal linkage (i.e. it won't be global). (For more information on declarations see http://www-ccs.ucsd.edu/c/declare.html The address operator, &, is used to create a pointer to the data structure which is passed to the other functions.
#include "defs.h"
#include "get_data.h"
#include "use_data.h"

static DATA data;

int main()
{
    get_data(&data);
    modify_data(&data);
    display_data(&data);
 
    return 0;
}
defs.h:
defs.h contains the combined structure data type declaration and typedef declaration to create the new type name, DATA. (See my notes on struct and typedef.) It is included in all the files that declare the data structure or a pointer to the data structure.
#ifndef DEFS_H_
#define DEFS_H_

typedef struct 
{
    int item1;
    int item2;
    float item3;
    float item4;
} DATA;

#endif /*DEFS_H_*/
get_data.c:
get_data.c contains the function to initially fill the data structure. It is passed a pointer to the data structure defined in main.c. It uses the structure pointer operator, ->, to access the members of the structure pointed to by data_ptr. data_ptr is the only local variable in this function-- the data structure being filled is the same one that was defined in main.c.
#include "defs.h"

int get_data(DATA *data_ptr)
{
    data_ptr->item1 = 1;
    data_ptr->item2 = 2;
    data_ptr->item3 = 3.0;
    data_ptr->item4 = 4.0;
 
    return 0;
}
use_data.c:
use_data.c contains the functions that use and modify the data in the data structure. They are both passed a pointer to the structure similar to get_data.c.
#include 
#include "defs.h"

int modify_data(DATA *data_ptr)
{
    data_ptr->item2 += 1;
    data_ptr->item4 += 1.0;
 
    return 0;
}

int display_data(DATA *data_ptr)
{
    printf("data.item1: %d\n", data_ptr->item1);
    printf("data.item2: %d\n", data_ptr->item2);
    printf("data.item3: %f\n", data_ptr->item3);
    printf("data.item4: %f\n", data_ptr->item4);
 
    return 0;
}
get_data.h
get_data.h and use_data.h contain the function declarations (function prototypes) and should be included wherever the functions are used.
#ifndef GET_DATA_H_
#define GET_DATA_H_

int get_data(DATA *data_ptr);

#endif /*GET_DATA_H_*/
use_data.h
#ifndef USE_DATA_H_
#define USE_DATA_H_

int modify_data(DATA *data_ptr);
int display_data(DATA *data_ptr);

#endif /*USE_DATA_H_*/
Output:
Running the program produces the following output:
data.item1: 1
data.item2: 3
data.item3: 3.000000
data.item4: 5.000000
Other notes:
Header files should only contain declarations. They should not contain variable definitions because if the header file is included in multiple locations there would be multiple definitons of the same variable. (See this thread in the comp.lang.c newsgroup.)

Diagram:


Revision 2 based on comments from this thread on the comp.lang.c newsgroup:


Revision 3: Updated based on more comments from the newsgroup. Also, I think my original #includes were OK.

[Read the full post...]

Notes on typedef and struct



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/02/notes-on-struct-and-typedef/

You should be redirected in 2 seconds.



Here are my notes on using C's struct and typedef keywords.

struct

To create a C structure, first create a new structure type:
struct my_struct_tag
{
    int member1;
    float member2;
};
Note that in the example above, the struct keyword is used only to create a new data type but it has not defined any variables yet.

To define new varaibles of this structure type, do this:
struct my_struct_tag mystruct1;
struct my_struct_tag mystruct2;

You can optionally combine these two steps and create the new data type and define variables:
struct my_struct_tag
{
    int member1;
    float member2;
} mystruct1, mystruct2;
In this case the structure tag my_struct_tag is optional.

typedef

From the K&R book, the typedef keyword is used to create new data type names. For example:
typedef int Length;

The name Length is a synonym for int and can be used as follows:
Length len, maxlen;

The typedef keyword can also be used to rename struct data types. Using the example above:
typedef struct my_struct_tag MyStructType;
MyStructType mystruct1;
MyStructType mystruct2;
This creates a new data type name, MyStructType which is synonymous with the struct my_struct_tag data type, and then defines two variables, mystruct1 and mystruct2.

You could combine the creation of the type name with the creation of the struct data type:
typedef struct my_struct_tag
{
    int member1;
    float member2;
} MyStructType;
Like the previous example, this creates a new structure data type and creates a new type name, MyStructType which is synonymous with struct my_struct_tag. Like the combo example in the struct section above, the structure tag, my_struct_tag is optional. However, unlike that example, the identifier following the last curly brace (MyStructType) is the new type name and not a new variable. To define the variables, use:
MyStructType mystruct1;
MyStructType mystruct2;
See also How to share non-global C data structures
Technorati tags:
[Read the full post...]

Example using bison and flex with cygwin on Windows



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/02/example-using-bison-and-flex-with/

You should be redirected in 2 seconds.



Here is an example of how to use bison and flex (yacc and lex) with cygwin on windows xp.
  1. Go to http://www.cygwin.com/, install Cygwin including bison 2.3-1, flex 2.5.4a-3, gcc-core 3.4.4-1, and make 3.81-1.

  2. Create a file called "simple.flex" in "c:\temp":
    %{                                                                                          
    #include "simple.tab.h"
    extern int line_number;
    %}
    %option noyywrap

    %%
    "float" { printf("FROM FLEX FLOAT %s\n", yytext); return FLOAT; }
    "int" { printf("FROM FLEX INT %s\n", yytext); return INT; }
    [;] { return *yytext; }
    [_a-zA-Z][_a-zA-Z0-9]* { printf("FROM FLEX IDENTIFIER: %s\n", yytext); return IDENTIFIER; }
    [ \t\r]+ /* eat up whitespace */
    [\n] { line_number++; }
    %%

  3. Create a file called "simple.y" in "c:\temp":
    %{                                                                                   
    #include
    #include "simple_shared.h"
    #define YYSTYPE char *
    int yydebug=1;
    int indent=0;
    char *iden_dum;
    %}
    %token FLOAT
    %token INT
    %token IDENTIFIER

    %% /* Grammar rules and actions follow */
    declaration:
    type_specifier identifier_dum ';'
    { printf("%3d: FROM BISON declaration\n", line_number); }
    ;
    type_specifier:
    FLOAT
    { printf("%3d: FROM BISON FLOAT\n", line_number); }
    | INT
    { printf("%3d: FROM BISON INT\n", line_number); }
    ;
    identifier_dum:
    IDENTIFIER
    { iden_dum = $1; printf("%3d: IDENTIFIER: %s\n", line_number, &iden_dum); }
    ;
    %%

    main ()
    {
    yyparse ();
    }

  4. Create a file called "simple_shared.h" in "c:\temp":
    int line_number=1;

  5. Create a file called "Makefile" in "c:\temp":
    simple: lex.yy.o simple.tab.o           
    gcc -o simple $^

    simple.tab.h: simple.y
    bison --debug --verbose -d simple.y

    simple.tab.c: simple.y
    bison -d simple.y

    lex.yy.c: simple.flex simple.tab.h
    flex simple.flex

  6. Create a file called "input.c" in "c:\temp":

  7. float variable;


  8. Open a Cygwin bash shell.
  9. "cd /cygdrive/c/temp"
  10. "make"
  11. "./simple.exe < input.c"

You should get some output like this:
$ ./simple.exe < input.c                      
Starting parse
Entering state 0
Reading a token: FROM FLEX FLOAT float
Next token is token FLOAT ()
Shifting token FLOAT ()
Entering state 1
Reducing stack by rule 2 (line 21):
$1 = token FLOAT ()
1: FROM BISON FLOAT
-> $$ = nterm type_specifier ()
Stack now 0
Entering state 4
Reading a token: FROM FLEX IDENTIFIER: variable
Next token is token IDENTIFIER ()
Shifting token IDENTIFIER ()
Entering state 6
Reducing stack by rule 4 (line 27):
$1 = token IDENTIFIER ()
1: IDENTIFIER:
-> $$ = nterm identifier_dum ()
Stack now 0 4
Entering state 7
Reading a token: Next token is token ';' ()
Shifting token ';' ()
Entering state 8
Reducing stack by rule 1 (line 17):
$1 = nterm type_specifier ()
$2 = nterm identifier_dum ()
$3 = token ';' ()
1: FROM BISON declaration
-> $$ = nterm declaration ()
Stack now 0
Entering state 3
Reading a token: Now at end of input.
Stack now 0 3
Cleanup: popping nterm declaration ()
 Technorati tags: , , , ,

[Read the full post...]

How to setup the MinGW gcc tools for your Managed Make C Project in CDT 3.1 and Eclipse 3.2



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/01/how-to-setup-mingw-gcc-tools-for-your/

You should be redirected in 2 seconds.



Here is a good article about how to setup MinGW tools with CDT and Eclipse. However I got one error when I setup my project. I got a
"/usr/bin/sh: c:mingwbinmingw32-gcc: command not found"
error. This was because I had "c:\cygwin\bin" in my path. To remedy this, you can set the "PATH" environment variable for your project. This will allow you to search the "c:\mingw\bin" path instead of the "c:\cygwin\bin" path without changing your path outside of Eclipse. This is also the solution if you have the wrong "include" directories listed in your "Includes" folder. E.g., if you have cygwin directories in your "Includes" folder, probably the cygwin gcc command is being used. See also my other post, How to set the include paths for gcc in a Managed Make project in Eclipse 3.2.1 and CDT 3.1

Update 2/5/2007:
You will also likely get a warning which says: Error launching 'cygpath' command'
See my post, Eclipse/CDT bug: Error launching 'cygpath' command about that.
To setup a GDB debugger, see my post, How to use the mingw gdb debugger with Eclipse 3.2 / CDT 3.1
Also, here is another good tutorial about setting up CDT: http://max.berger.name/howto/cdt/

Here are the detailed steps:
  1. Right-click on your project and select "Properties"
  2. Select "C/C++ Build" from the sidebar
  3. Click the "Tool Settings" tab
  4. Click the "GCC C Compiler" and enter "mingw32-gcc" in the "Command:" field
  5. Click the "GCC C Linker" and enter "mingw32-gcc" in the "Command:" field
  6. Click the "Build Settings" tab
  7. Uncheck the "Use default command" checkbox
  8. Replace "make" with "mingw32-make -k"
  9. Click the "Environment" tab; click the "Configuration" tab
  10. Click the "New" button
  11. From the "Name" dropdown box, select "Path"
  12. In the "Value" field, delete the contents and enter "C:\mingw\bin"
  13. In the "Delimiter" field, leave it as ";"
  14. In the "Operation" field, select "Replace"
  15. Click "OK"; click "OK"

[Read the full post...]

How to use Eclipse and CDT to edit C source files



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/01/how-to-use-eclipse-and-cdt-to-edit-c/

You should be redirected in 2 seconds.



Eclipse is a good integrated development environment rivaling Microsoft Visual Studio 2005. I have Visual Studio 2005 installed on my computer, though for some reason, I don't care to use it. Eclipse originally was used for Java development but now includes plugins for C/C++, Python, Perl, and many others. I use the Pydev plugin for Python development and it is good.

I am using Tornado 2.2 to develop C code for VxWorks. The editor in Tornado isn't the greatest, so I want to edit my code in Eclipse with the CDT plugin. I will still be using Tornado to build the projects, so instead of using a Standard or Managed Make Project, I just created a folder which linked to my source files. Note that you may get messages in Tornado that say "This file has been changed outside the source editor. Do you want to reload it?" Just make sure you don't have any unsaved changes from Tornado and click "Yes". Or just make sure all your source code windows are closed in Tornado. I know this isn't the most elegant solution, but it will have to do unless we upgrade to VxWorks 6 and Workbench.

Update 2/13/07: I've found a better way to use Eclipse with Tornado projects. See my post How to use Tornado GNU tools with Eclipse/CDT for how to use Eclipse to edit *and build* your Tornado project.

Here are the steps:
  1. Start with your .c and .h files in a directory called "c:\sofeng\proj\stuff"
  2. Download and install eclipse-SDK-3.2.1-win32.zip from http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.2.1-200609210945/eclipse-SDK-3.2.1-win32.zip
  3. Download and install org.eclipse.cdt-3.1.1-win32.x86.zip from http://download.eclipse.org/tools/cdt/releases/callisto/dist/3.1.1/
  4. Run "eclipse.exe"
    5. From the menu: "Window" -> "Open Perspective" -> "Other..." -> "C/C++" -> "OK"
  5. From the menu: "File" -> "New" -> "Other..."
  6. Under "General", select "Project"
  7. Click "Next"
  8. In the "Project name:" field, type "dummy". Leave the "Use default location" box checked.
  9. Click "Finish"
  10. From the menu: "File" -> "New" -> "Folder"
  11. In the "Enter or select the parent folder:" enter or select the "dummy" project you just created.
  12. Click the ">> Advanced" button
  13. Click the "Link to folder in the file system" checkbox and enter "c:\sofeng\proj\stuff" or "Browse..." to that location.
  14. Click "Finish"
NOTE: If you do not see the ">> Advanced" button, follow these steps:
  1. From the "Window" menu, select "Preferences..."
  2. Go to "General" > "Workspace" > "Linked Resources" and check "Enable linked resources"
  3. Click "OK"

[Read the full post...]

About

This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

http://www.saltycrane.com/blog/.

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.