Page 1 of 20

C++/C programming discussion

Posted: Mon Mar 01, 2010 9:46 pm
by Scott
Curious to what GUI framework are recommended by any C++ programmers out there. QT, OpenGL, or something completely different.

Re: C++ GUI Frameworks

Posted: Tue Mar 02, 2010 2:43 pm
by Sam
Well I only can programme with C (currently) but I write the code out and use compilers. If you decide you want to use one I know the compiler I use currently (gcc) is the most recomended and widly used complier.

other than that I can not be of much help.

Re: C++ GUI Frameworks

Posted: Tue Mar 02, 2010 3:19 pm
by Matthew
I'm using OpenGL with python for my game. It's a pain to work but at least it is fast.

Re: C++ GUI Frameworks

Posted: Tue Mar 02, 2010 9:57 pm
by Scott
Tretarn wrote:Well I only can programme with C (currently) but I write the code out and use compilers. If you decide you want to use one I know the compiler I use currently (gcc) is the most recomended and widly used complier.

other than that I can not be of much help.
I use Dev C++ which I think uses gcc.
CrytekUK.info wrote:I'm using OpenGL with python for my game. It's a pain to work but at least it is fast.
I'll give it a look. I only know some basic C++ but am steadily making progress.

Re: C++ GUI Frameworks

Posted: Wed Mar 03, 2010 1:59 pm
by Matthew
OpenGL has one good thing about it. It doesn't rely on many programming features. It's basically a bunch of function calls. It isn't object based. That also means it's easy to understand OpenGL from many examples in different languages. Converting Python OpenGL code to C++ OpenGL code is simply done by adding ";" on the end of all functions most of the time. If you struggle with it, I may be able to give limited help but I'm new to it as well.

Re: C++ GUI Frameworks

Posted: Mon Mar 22, 2010 7:36 pm
by Matthew
I'm trying to use pyglet right now. I'm getting errors with the cTypes module. It doesn't like my integers anymore after implementing pyglet. This is for the second parameter of glBindFramebufferEXT(). :?

Re: C++ GUI Frameworks

Posted: Sat Apr 17, 2010 10:28 pm
by Scott
I'm having trouble with functions...

When I do this:

Code: Select all

#include <iostream>

using namespace std;

unsigned long int Perimeter(unsigned short int len, unsigned short int wid);

int main()
{
    unsigned short int len = 0;
    unsigned short int wid = 0;
    unsigned short int perimeter = 0;
    perimeter = Perimeter(len,wid);
       
    cout << "Please enter a side length...\n";
    cin >> len;
    cout << "Now a side width...\n";
    cin >> wid;
    cout << "Thanks!\n";
    cout << "The perimeter is: " << perimeter << "\n";
    
    char response;
    cin >> response;
    return 0;
}

unsigned long int Perimeter(unsigned short int len, unsigned short int wid)
{
         return (2*len) + (2*wid);
}
Perimeter always equals 0. But if I move "perimeter = Perimeter(len,wid);" to here:

Code: Select all

#include <iostream>

using namespace std;

unsigned long int Perimeter(unsigned short int len, unsigned short int wid);

int main()
{
    unsigned short int len = 0;
    unsigned short int wid = 0;
    unsigned short int perimeter = 0;
       
    cout << "Please enter a side length...\n";
    cin >> len;
    cout << "Now a side width...\n";
    cin >> wid;
    cout << "Thanks!\n";
    
    perimeter = Perimeter(len,wid);
    
    cout << "The perimeter is: " << perimeter << "\n";
    
    char response;
    cin >> response;
    return 0;
}

unsigned long int Perimeter(unsigned short int len, unsigned short int wid)
{
         return (2*len) + (2*wid);
}
It works. So I figured out the problem (by debugging :() but I don't know why it now works. Any info would be appreciated. :)

Re: C++ GUI Frameworks

Posted: Sun Apr 18, 2010 6:39 am
by Sam
I think what you've done is quite simple but my C++ syntax knoledge is non existant. But I think its similar to C.

Anyway, in code 1 you call on the function right away, which then returns a value based on length and width. However, you have not let the user define those yet, so the computer just takes them to be thier origional value, 0. However this should have atleast returned a value of 4, as (2+0) + (2+0) = 4.

In code 2 you let the user define the values before calling on the function, giving the correct value.

Hope this helps.

Re: C++ GUI Frameworks

Posted: Sun Apr 18, 2010 9:17 pm
by Scott
That does help but what I still don't understand is that

Code: Select all

perimeter = Perimeter(len,wid);
doesn't do anything but set the value of perimeter. So then why does it go ahead and run the function? Is it just because the parameters have not been set so that variable perimeter can't really be defined yet?

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 11:40 am
by Matthew
Perimeter(len,wid) is a function call. That means it will pass the arguments len and wid to the Perimeter function and run it with those arguments. The function then returns a value. Your original code called the function before you set the len and wid variables with cin, hence the function ran with the arguments set to zero and gave 0 as the result.

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 11:48 am
by Sam
Thats exactly how I would call on a function in C. What your saying is

perimeter = the result of the function

so the compiler will run the function immediatly on seeing this to find the perimeter. It will then use any values already defined before this point in the calculations.

I miss read the * sign before. so actually the calculations will be:
as your values are defined as 0.
perimeter = (2*0) + (2*0) = 0

but when you moved it downwards, you gave the compiler a chance to see the user defined values and the calculations come out as intended.

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 11:52 am
by Sam
CrytekUK.info wrote:Perimeter(len,wid) is a function call. That means it will pass the arguments len and wid to the Perimeter function and run it with those arguments. The function then returns a value. Your original code called the function before you set the len and wid variables with cin, hence the function ran with the arguments set to zero and gave 0 as the result.
beat me to it :lol:

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 1:54 pm
by Scott
So the defining of perimeter takes the variables that are already available? That would make sense to me :)

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 5:13 pm
by Sam
yeah, it'l take anything defined up to that point, sometimes when you forget to define a variable your complier might take some random memory addresses, so you end up with some crazy outputs.

Core dumps(aka segmentation faults) are also fun.

Re: C++ GUI Frameworks

Posted: Mon Apr 19, 2010 5:32 pm
by Matthew
Scott wrote:So the defining of perimeter takes the variables that are already available? That would make sense to me :)
Defining the function at the bottom doesn't run the function at the bottom. Functions are only run when they are called with the syntax function_name();
Tretarn wrote:Core dumps(aka segmentation faults) are also fun.
Well core dumps aren't the same thing as segmentation faults but I can see possibly why you'd want to dump the memory if you got a segmentation fault.

If you get a segmentation fault, it's probably due to an overflow of an array. Simple debugging of the application can solve these errors.

You need to be careful with overflows because they an cause security problems with your applications.

C++ should have some form of overflow protection. I don't know why it's so widely used because of this. I have heard of some compilers that analyse code for potential overflow errors but I don't think they are widely used and can't protect against variable inputs.

Modern operating systems have memory protection but there are huge security risks when operating systems have overflow problems.