You are not logged in.

#1 2012-08-29 10:29:57

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

gint main

I was skimming through the source of a GTK application, and I noticed that their main function was declared like this:

gint main(gint argc, gchar **argv)

Is there a reason to do this?

Offline

#2 2012-08-29 11:20:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: gint main

No, no reason at all and it's one of my many annoyances with GTK trying to reinvent the wheel, but by not changing it at all, they only add confusion.

The relevant line from that link:

Types which correspond exactly to standard C types, but are included for completeness - gchar, gint, gshort, glong, gfloat, gdouble.

Or, the other relevant line that just makes my head hurt:

typedef int    gint;

This adds no functionality, no options, no anything.  It's just branding at the cost of clarity (and an extra character).

Last edited by Trilby (2012-08-29 11:47:48)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2012-08-29 11:58:28

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: gint main

Well... That seems ridiculous. hmm

Offline

#4 2012-08-29 13:04:34

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: gint main

seriously? I mean they must have had some kind of reason to do this. I can't imagine that a dozen of gnome devs agree "yeah, let's prefix everything with a g for no reason, that's totally awesome and cool!"

... or are the gnome devs actually as retarded as some people claim?

Offline

#5 2012-08-30 17:41:35

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: gint main

65kid wrote:

I can't imagine that a dozen of gnome devs agree "yeah, let's prefix everything with a g for no reason, that's totally awesome and cool!"

It's a good thing KDE would never do anything so ridiculous! /s

Offline

#6 2012-08-31 03:54:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,740

Re: gint main

moderator comment:  Behave guys ... smile


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#7 2012-08-31 22:21:34

Diaz
Member
From: Portugal
Registered: 2008-04-16
Posts: 366

Re: gint main

It's a way to support future changes if they are ever needed.

This way they can change the implementation details of a gint or any other g_type and it will not affect a program if it always uses those types.

Pretty simple logic. The only "problem" is that currently they are just alias to the same type smile

Last edited by Diaz (2012-08-31 22:29:15)

Offline

#8 2012-09-01 00:52:27

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: gint main

Diaz wrote:

It's a way to support future changes if they are ever needed.

This way they can change the implementation details of a gint or any other g_type and it will not affect a program if it always uses those types.

Well, not if you do "gint main()". UB waiting to happen.

BTW, my last post was in jest, not meant to foment controversy. Sorry if it came across wrong.

Offline

#9 2012-09-01 21:41:24

drobole
Member
From: Norway
Registered: 2012-07-23
Posts: 125

Re: gint main

This is actually a very common thing to do.

By creating aliases like that, if they ever need to change a type, say from int32 to int64 in the future, it can be done on a single line, instead of running a find-and-replace on every file in the code base, not to mention every application targeting GTK.

Offline

#10 2012-09-01 21:45:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: gint main

But are there cases (in which one could use gtk) where main should return something other than an int?  If one uses "gint main()" and at some point gtk changes the definition of gint, that program will no longer compile.  Main needs to return an int.  So by using "gint main()" you need to assume that gint will always just be int, or that you program may fail to compile.

Last edited by Trilby (2012-09-01 21:45:19)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2012-09-01 21:54:33

drobole
Member
From: Norway
Registered: 2012-07-23
Posts: 125

Re: gint main

Trilby wrote:

But are there cases (in which one could use gtk) where main should return something other than an int?  If one uses "gint main()" and at some point gtk changes the definition of gint, that program will no longer compile.  Main needs to return an int.  So by using "gint main()" you need to assume that gint will always just be int, or that you program may fail to compile.

Thats a good point.
I'm not convinced that it actually should be gint in that case

Offline

#12 2012-09-01 22:04:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: gint main

I don't have so much of a problem with having a gint type (though it is fun to poke fun at) but the gint main is what I really see as off.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2012-09-02 00:59:33

Diaz
Member
From: Portugal
Registered: 2008-04-16
Posts: 366

Re: gint main

Actually that seems weird wink

Offline

Board footer

Powered by FluxBB