Mac Forums

Mac Forums (
-   OS X - Apps and Games (
-   -   Help with Text Wrangler (

Hexen 01-17-2012 01:58 AM

Help with Text Wrangler
I've been using Text Wrangler for a day and I've programmed in Perl, Python, and Shell Script already, but when I try to program in C++, I'm stuck in a rut. If I include the shebang line #!/usr/bin/gcc I get a C++ error that says "invalid preprocessing directive." If I remove the shebang line, I get a Text Wrangler error. Anybody know how to get rid of these errors?

Dysfunction 01-17-2012 03:47 AM

Ohhhhhhhh remove the shebang, save the file in textwrangler then compile it. Yea, #!/usr/bin/gcc won't work.. and I don't think textwrangler will actually run the compiler

vansmith 01-17-2012 08:56 AM

You really only need the shebang line for interpreted languages. It works to tell your shell how to execute a script if it has executable privileges. For example, let's say you have a Python script and you make it executable (so you don't have to invoke the Python interpreter). The shebang at the beginning tells the shell that this is a Python script that needs to be interpreted by Python.

Since C/C++/Obj-C compile to native code, the shebang is useless since no interpreter needs to be invoked. In those languages, the hash mark actually signifies something else (preprocessor directives). Valid examples include #define and #include and invalid examples include your shebang line.

As dys said, remove it and try again.

Dysfunction 01-17-2012 10:24 AM

If you want to run your code, from within your development software, you're gonna need an IDE.. well, you already have xCode :)

vansmith 01-17-2012 10:32 AM


Originally Posted by Dysfunction (Post 1356753)
If you want to run your code, from within your development software, you're gonna need an IDE.. well, you already have xCode :)

Pfft, Vim can handle it just fine:

:!gcc %

Or, better yet:

:!gcc % -o name_of_app

Who needs an IDE? :P

Dysfunction 01-17-2012 11:33 AM

hey, I may be a cli guy... but I still don't feel right pushing people into vi :D

vansmith 01-17-2012 12:52 PM

macvim - Vim for the Mac - Google Project Hosting - Problem solved! :P

Hexen 01-17-2012 02:14 PM

That's what I had to do. I had to compile it through Terminal using g++ -o, and then running the executable. I hate C++, I've been trying to configure Eclipse to run it. When I first tried I couldn't build the binaries, then after that I get an error message about the architecture that I read was caused by OS X being 64-bit. So I tried Text Wrangler, and I had problems too! But I have it now, I guess. I just have to turn all my files into executable files, but I made it easier on myself by creating aliases to do it easier and quicker. I know everyone says to use Xcode, but truth be told, I don't really like Xcode. It's too bloated for me;) Thanks for all the replies.

vansmith 01-17-2012 03:00 PM


Originally Posted by Hexen (Post 1356853)
I just have to turn all my files into executable files, but I made it easier on myself by creating aliases to do it easier and quicker.

There's no way around this - C++ is a compiled language. You can not interpret C++ code for it wasn't designed that way and never has been.

If you hate C++, might I ask why you're using it?

Hexen 01-17-2012 03:34 PM

Because I read that it's the lingua franca of programming languages and I've seen it for myself. Like I said before, I learned Java last semester and I can understand bits and pieces of other languages because of Java's similarities to C/C++, and I like that. Not only that, but from what I've read, C++ has a wider possibility of applications than Java. Yeah I know, all of this is based on other people's testimonials, but I take their word for it. Besides, it can't hurt to know another language, right? I guess I don't hate C++, because I really haven't been able to program in it.

vansmith 01-17-2012 03:51 PM

I suppose it's the lingua franca for certain requirements but this all depends on what you want to accomplish. If you want to do lower level programming, C is the way to go. For other projects, C is a terrible choice (relationally). What kinds of things do you want to develop?

Hexen 01-17-2012 04:01 PM

I have no idea yet, I have a year and a half to figure it out though:) Probably programs on a professional level, but I also have an interest in programming hardware (musical applications like the Noise Toy), in which case I assume C would be good since it's lower level. Honestly, I'm just trying to learn as much as possible right now.

vansmith 01-17-2012 04:12 PM

Oh, please don't let my questions and comments deter you from learning as much as possible. That's very much not the case. Learn as much as you can now while you have the freedom to do so. :)

If you're going to be doing hardware level programming, the "C languages" are definitely worth some attention (and Assembly depending how "far down" you want to go). You may not like it for some higher level stuff but it can definitely be used since most major programs involve a "C language" somewhere. I can't speak to your preference though - that's all you.

Admittedly, part of my questioning comes out of my dislike for C/C++/Obj-C and strong preference for Python and Javascript. ;)

Hexen 01-17-2012 04:43 PM

Ha! Hopefully the freedom doesn't ever go away...

I don't want to even think about Assembly, there is no way that I would ever want to go that far. I'll be happy learning C in some variation. But I've been playing around with C++ all day--it's my last day of vacation, and I'm programming!--and it does seem like it's not the best language for higher level tasks, but I'm sure it does have it's applications.

I've been looking into Python too. I have Ubuntu installed as a Virtual Machine on my Mac, and I've looked at some of the files and it looks like a promising language. I've played around with it a bit on Terminal, but I'm looking for a good tutorial at the moment.

What do you have against C? I've seen a lot of people on various forums that have nothing good to say about C.

vansmith 01-17-2012 06:05 PM

It's unforgiving and doesn't have a garbage collector. I also don't like the syntax but that's a fairly minor point in the grand scheme of things.

All times are GMT -4. The time now is 08:06 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.