Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.
I hope this hasn't been asked already, I looked for a little on google and the beginning of this thread but didn't find anything.

I was wondering how to turn a C++ file into an actual application. Everything I do now just compiles into an a.out and i can run that through the command line but I was hoping I could actually make something that I could double click and open a little window. It wouldn't even have to look fancy, just a blank white window would be awesome.

PS. I'm using a Mac with Xcode and TextMate but I also have a windows machine at the ready. So suggestions for either would be awesome.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
"a.out" is an actual application. It's the default name in gcc for an executable if you don't specify one.

By "double click and open a little window", are you referring to a terminal (command line) window, or an actual GUI window? In the case of the former, what you have should already work. In the latter, you'll need to start learning a GUI API (no easy feat). Which API you pick depends on which platform(s) you want to develop for.

EDIT: the OP now has a list of GUI libraries, shamelessly stolen from Professor Science's reply on the first page. :)

Avenging Dentist fucked around with this message at 22:52 on Mar 24, 2008

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.
drat, I was hoping there would be something a little easier than learning an API but oh well.

I was going to use it cross platform because my main computer is a Mac and all of my friends run windows. I wanted to make an 'application' so that I could make a little program just messing around and send it to them to use/make jokes about/help me improve my programming, stuff like that.

Well, I'll just start checking out some of these sites. Thanks.

Incoherence
May 22, 2004

POYO AND TEAR

BraggPxnk posted:

drat, I was hoping there would be something a little easier than learning an API but oh well.

I was going to use it cross platform because my main computer is a Mac and all of my friends run windows. I wanted to make an 'application' so that I could make a little program just messing around and send it to them to use/make jokes about/help me improve my programming, stuff like that.

Well, I'll just start checking out some of these sites. Thanks.
The easiest way to do what you're describing is to switch to Java.

ColdPie
Jun 9, 2006

Incoherence posted:

The easiest way to do what you're describing is to switch to Java.

This is true, actually, and something I hadn't thought of when I was trying to come up with a reply. Java's UI may be butt-ugly, but you'll only have to code it once no matter which platform you plan to run it on. Since it sounds like you're just playing around with programming basics with your friends, Java might be ideal. Plus, Java and C++ are similar enough that you can more or less transfer what you learn from one to the other freely, at least for the basic stuff.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
As long as you're using a cross-platform API, the amount of rewriting you need to do should be minimal. wxWidgets, for instance, uses native controls and supports a wide variety of operating systems.

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.

Avenging Dentist posted:

As long as you're using a cross-platform API, the amount of rewriting you need to do should be minimal. wxWidgets, for instance, uses native controls and supports a wide variety of operating systems.

The first one I looked at was wxWidgets is the first one that I looked at and downloaded. It looks pretty good, I'm just not sure exactly what to do with it. I unziped the file and just kinda looked at the 'install' docs. I'll have to browse their website (and google) later and try to figure exactly what to do.

I have heard a lot about how Java is a lot like C++ and I always considered learning it. But I don't really feel like tackling another language right now. I found a free online course on Ruby and I'm just kinda palin' around with that seeing if I want to try and get good at it.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

BraggPxnk posted:

I have heard a lot about how Java is a lot like C++ and I always considered learning it.

They have a lot of syntactical similarities, and to a total beginner, they're pretty similar, but when you start getting into more advanced things, they can be very different, especially in terms of design philosophy.

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.

Avenging Dentist posted:

They have a lot of syntactical similarities, and to a total beginner, they're pretty similar, but when you start getting into more advanced things, they can be very different, especially in terms of design philosophy.

Well...I've taken four classes on C++ already. That was about a year ago, and since then I have just been goofing off with it in my spare time. I wouldn't necessarily say that I have moved onto 'more advanced things' but I'd say that I am no longer a beginner.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

BraggPxnk posted:

drat, I was hoping there would be something a little easier than learning an API but oh well.

I was going to use it cross platform because my main computer is a Mac and all of my friends run windows. I wanted to make an 'application' so that I could make a little program just messing around and send it to them to use/make jokes about/help me improve my programming, stuff like that.

Well, I'll just start checking out some of these sites. Thanks.

I'm a big fan of Python + Qt, although if one of the goals of this is to improve your C++ programming skills, just plain C++ and Qt would be more appropriate.

coods
May 2, 2005

JoeNotCharles posted:

I'm a big fan of Python + Qt, although if one of the goals of this is to improve your C++ programming skills, just plain C++ and Qt would be more appropriate.

I'm going to also suggest using Qt with C++.

cliffy
Apr 12, 2002

I'm trying to do the following:

code:
template <typename T>
class Foo
{
public:
    Foo ();
private:
    friend class T;
};
but according to the standard, you cannot declare a template parameter to be a friend. I'm trying to figure out the best way to do this without using friend. The reason I wanted to do this is that T will be a policy type, and having access to Foo's guts is natural. Any ideas?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

CasualCliffy posted:

but according to the standard, you cannot declare a template parameter to be a friend.

I don't see anything in the standard that says this, except that default template parameters can't be used in friend template declarations.

That Turkey Story
Mar 30, 2003

CasualCliffy posted:

I'm trying to do the following:

code:
template <typename T>
class Foo
{
public:
    Foo ();
private:
    friend class T;
};
but according to the standard, you cannot declare a template parameter to be a friend. I'm trying to figure out the best way to do this without using friend. The reason I wanted to do this is that T will be a policy type, and having access to Foo's guts is natural. Any ideas?

If you really want this, put the implementation of your class into a private base, then, from inside Foo, pass off that base to T so that it may access the implementation.

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.

coods posted:

I'm going to also suggest using Qt with C++.

I've been compiling Qt all day :(

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

That Turkey Story posted:

If you really want this, put the implementation of your class into a private base, then, from inside Foo, pass off that base to T so that it may access the implementation.

It looks like Comeau will let you do something like what he wanted with C++0x extensions on. Did the standard change in this regard?

Lexical Unit
Sep 16, 2003

I've been asking questions in this thread about this code I'm writing to help me learn to be a better C++ programmer for a while, here's what I've come up with thus far:

trie.h
main.cpp
QUnit.h
Edit: moved code from codepad.org to permanent hosting

So who wants to tell me how absolutely terrible my design/style/code is? :shobon:

Lexical Unit fucked around with this message at 01:17 on Mar 26, 2008

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.

BraggPxnk posted:

I've been compiling Qt all day :(

Ok, now I'm starting to get worried. I started compiling Qt at around 10 this morning and its still running at 7:30pm. Is this normal?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Lexical Unit posted:

I've been asking questions in this thread about this code I'm writing to help me learn to be a better C++ programmer for a while, here's what I've come up with thus far:

trie.h

So who wants to tell me how absolutely terrible my design/style/code is? :shobon:
This is kind of gross:
code:
#if !defined (NO_BOOST)
  return boost::lexical_cast<std::string> (value).length ();
#else
  std::ostringstream oss;
  oss << value;
  return oss.str ().length ();
#endif
Not just because of the conditional compilation alone, but because boost::lexical_cast<>() throws an exception that won't be thrown by the std::ostringstream version.

Lexical Unit
Sep 16, 2003

Ah good point, that hadn't crossed my mind. Originally I had just the lexical_cast version but then I thought, "shouldn't I be nice and support compiling when boost isn't installed?" and that prompted me to do what I did there. I'm not sure how I'd make the stringstream version throw the same exceptions in the same cases without basically re-writing boost::lexical_cast though. Do you think it would be better to just leave out all the conditional compiling and just flatly require boost?

ColdPie
Jun 9, 2006

BraggPxnk posted:

Ok, now I'm starting to get worried. I started compiling Qt at around 10 this morning and its still running at 7:30pm. Is this normal?

Is it actually doing anything? Check the command-line output, doing one action shouldn't take more than a minute so make sure lines are scrolling. According to a quick google, 2 hours on a Pentium 2 is considered "slower than normal," and others are reporting ~10 minute compile times.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Lexical Unit posted:

Do you think it would be better to just leave out all the conditional compiling and just flatly require boost?

Just require Boost. Speaking of, have you been following the Trie discussion on the Boost developers list?

Bush Muncher
Aug 25, 2005

What? 100 thtitcheth? 7 mithing teeth? Eh, I'll just thkate it off.

ColdPie posted:

Is it actually doing anything? Check the command-line output, doing one action shouldn't take more than a minute so make sure lines are scrolling. According to a quick google, 2 hours on a Pentium 2 is considered "slower than normal," and others are reporting ~10 minute compile times.

It is actually been doing something. I've been checking the output a lot and it keeps on doing its think. I did the './configure' and the 'make'. It's doing the makefiles now. I'm using a 1Ghz G4 Mac running leopard.

Lexical Unit
Sep 16, 2003

Avenging Dentist posted:

Speaking of, have you been following the Trie discussion on the Boost developers list?
Nope, not at all. But I just subscribed.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Be warned, you'll be inundated with mail unless you check your mail everyday. The Boost developer's list is incredibly busy. I should set up some more filters for it.

Lexical Unit
Sep 16, 2003

Well, I'm already subscribed to the gcc, gcc-help, xorg, TAO, libstdc++, festival-talk, and boost-users lists, so a little more won't hurt. It gives me something to do during work down-time. Interesting that they're modeling it after std::map, I went with std::set instead. However I can certainly see why one modeled on map would be quite useful.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.
I came across this a year or two ago:

rob pike posted:

Simple rule: include files should never include include files. If instead they state (in comments or implicitly) what files they need to have included first, the problem of deciding which files to include is pushed to the user (programmer) but in a way that's easy to handle and that, by construction, avoids multiple inclusions. Multiple inclusions are a bane of systems programming. It's not rare to have files included five or more times to compile a single C source file. The Unix /usr/include/sys stuff is terrible this way.

There's a little dance involving #ifdef's that can prevent a file being read twice, but it's usually done wrong in practice - the #ifdef's are in the file itself, not the file that includes it. The result is often thousands of needless lines of code passing through the lexical analyzer, which is (in good compilers) the most expensive phase.

Just follow the simple rule.

It made sense at the time and I've followed this rule ever since (it's Rob Pike for Christ's sake). But when it comes to libraries it starts to get overly tedious for people using your library. You don't want to have a monolithic header file (think of the sockets library only used one header) but you also don't want them to have to read comments in your headers to find dependencies. What do other people do?

And yes, I do employ #ifdef guards on the header files as well.

haveblue
Aug 15, 2005



Toilet Rascal
I disagree. The author should determine dependencies and set them in stone once; the users should be able to bypass those just as they're bypassing whatever issues and complexities prompted them to use pre-existing code to address in the first place.



vvvvvvvv Uninitialized pointers?

haveblue fucked around with this message at 22:37 on Mar 26, 2008

GuyGizmo
Feb 26, 2003

stupid babies need the most attention
I've got a programming bug that's about to make me start pulling out my hair:

I'm writing a plugin in C++ for both the 32-bit and 64-bit Windows versions of Maya. When I compile and test the plugin in a 32-bit environment, it works great. In 64-bit Maya, it causes the whole program to crash, and I have no idea why. It's exactly the same code, and none of it *should* be sensitive to a platform change like that.

Furthermore, when trying to poke around or removing bits and pieces of my code to see if I can figure out what part is causing the crash, I start finding out that re-arranging trivial lines of code, or worse yet, changing the names of local variables can either cause the crash to happen at different places or not at all. Results are totally inconsistent. It makes no sense!

I loving hate errors like this. Does anyone know what the hell could cause a completely inconsistent crash like this?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Plastic Jesus posted:

I came across this a year or two ago:

That is possibly the stupidest thing I've read this year. Are you sure he wasn't trolling?

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

GuyGizmo posted:

I've got a programming bug that's about to make me start pulling out my hair:

I'm writing a plugin in C++ for both the 32-bit and 64-bit Windows versions of Maya. When I compile and test the plugin in a 32-bit environment, it works great. In 64-bit Maya, it causes the whole program to crash, and I have no idea why. It's exactly the same code, and none of it *should* be sensitive to a platform change like that.

Furthermore, when trying to poke around or removing bits and pieces of my code to see if I can figure out what part is causing the crash, I start finding out that re-arranging trivial lines of code, or worse yet, changing the names of local variables can either cause the crash to happen at different places or not at all. Results are totally inconsistent. It makes no sense!

I loving hate errors like this. Does anyone know what the hell could cause a completely inconsistent crash like this?

Unfortunately, plenty of things could be wrong: invalid assumptions about the size of ints/pointers, different alignment on structs or other memory, API calls that work slightly differently (in both windows AND maya)... the list goes on. :(

If you have a debugger and stack dumps though, it shouldn't be too significant a problem to track down the actual culprit.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Plastic Jesus posted:

I came across this a year or two ago:


It made sense at the time and I've followed this rule ever since (it's Rob Pike for Christ's sake). But when it comes to libraries it starts to get overly tedious for people using your library.
Sadly it's hard to elegantly do on anything that's not Plan 9. It's pretty much impossible to do in C++ when templates are invovled, and hard in standard C because of the unnecessarily fragmented standard and POSIX headers.

Avenging Dentist posted:

Are you sure he wasn't trolling?
Check out the Plan 9 source sometime. No #included includes, no #ifs.

Presto
Nov 22, 2002

Keep calm and Harry on.

Plastic Jesus posted:

I came across this a year or two ago:
I'm pretty much in the opposite camp: a header file should include all the other headers it needs. If I'm putting a function prototype into a header that needs a typedef'd type or whatever, then that header should include the header where the type is defined. If that means that stdio.h gets included 15 times in my .c file, oh well.

His only argument is that multiple inclusions slow down the compiler. My response would be: Yes? And?

floWenoL
Oct 23, 2002

Plastic Jesus posted:

I came across this a year or two ago:

Apparently, you don't know enough to check the dates on what you read on the internet as that was written in 1989. The line:

quote:

The result is often thousands of needless lines of code passing through the lexical analyzer, which is (in good compilers) the most expensive phase.

should have also raised a red flag as compilers these days skip files they see are entirely protected by an if guard.

floWenoL
Oct 23, 2002

Presto posted:

His only argument is that multiple inclusions slow down the compiler. My response would be: Yes? And?

And compile time is a major bottleneck for large C/C++ programs. Pike's advice might be outdated, but including (non-system) headers willy-nilly is a good way to kill compile performance.

ColdPie
Jun 9, 2006

Plastic Jesus posted:

I came across this a year or two ago:

This sounds sane to me, and it's something I always wondered about. But I never follow that rule for the following reason: how do you include types that are defined in other headers, in your header?

code:
//One.h

class One {
  int aMember;
};
code:
//Two.h

#include "One.h"

class Two {
  One anotherMember;
};
How can this situation be arranged so that Two.h does not include One.h, but the class Two still contains a member of type One?

Edit: #ifdefs truncated, but pretend they're there

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

ColdPie posted:

This sounds sane to me, and it's something I always wondered about. But I never follow that rule for the following reason: how do you include types that are defined in other headers, in your header?

code:
//One.h

class One {
  int aMember;
};
code:
//Two.h

#include "One.h"

class Two {
  One anotherMember;
};
How can this situation be arranged so that Two.h does not include One.h, but the class Two still contains a member of type One?

Edit: #ifdefs truncated, but pretend they're there

It can't. The compiler MUST know the size of One in order to compile Two. It can be done with a level of indirection, though:

code:
class One;

class Two
{
  One* one;
};
This works because pointers to any type are always the same size, and the compiler just needs reassurance that 'One' isn't a typo.

notMordecai
Mar 4, 2007

Gay Boy Suicide Pact?
Sucking Dick For Satan??

Freshman CS major. I am doing a very, very basic program to represent trees. What it does is the computer says a number from 1 to 20 and depending on the number given (the first number it will always say is "10"). The user enters if that is correct, lower, or higher. It's simple enough but I am getting a really loving annoying syntax error that is not letting progress further.

code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct guess_tree{
                  int node;
                  struct guess_tree* less;
                  struct guess_tree* more;
                  };
                  
struct guess_tree *start, *current_guess;

guess_tree list[21];

int i;

for (i = 1; i <= 20; i++) {
	list[i]->node = i;
}
It's telling me I have a syntax error before "for" in line 17. So help me god I cannot figure out what the gently caress I am doing wrong (unless of course I am having a retard moment).

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

notMordecai posted:

Freshman CS major. I am doing a very, very basic program to represent trees. What it does is the computer says a number from 1 to 20 and depending on the number given (the first number it will always say is "10"). The user enters if that is correct, lower, or higher. It's simple enough but I am getting a really loving annoying syntax error that is not letting progress further.

code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct guess_tree{
                  int node;
                  struct guess_tree* less;
                  struct guess_tree* more;
                  };
                  
struct guess_tree *start, *current_guess;

guess_tree list[21];

int i;

for (i = 1; i <= 20; i++) {
	list[i]->node = i;
}
It's telling me I have a syntax error before "for" in line 17. So help me god I cannot figure out what the gently caress I am doing wrong (unless of course I am having a retard moment).

If that's your entire file, then you're just dumping executable code in no-man's land. It needs to be in an execution path, like your main function for instance.

Adbot
ADBOT LOVES YOU

more falafel please
Feb 26, 2005

forums poster

Drx Capio posted:

It can't. The compiler MUST know the size of One in order to compile Two. It can be done with a level of indirection, though:

code:
class One;

class Two
{
  One* one;
};
This works because pointers to any type are always the same size, and the compiler just needs reassurance that 'One' isn't a typo.

It's dumb, but what it was suggesting was:
code:
// One.h
class One
{
    int x;
};
// end One.h

// Two.h
class Two
{
    One one;
};
// end Two.h

// main.cpp
#include "One.h"
#include "Two.h"

One one;
Two two;

int main()
{
    ...
}
But gently caress that.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply