coding style

Discussions about the internal structures of the game. You can also post here if you'd like to know how things really work (and don't know how to read C code).
Post Reply
gyboth
Site Admin
Posts: 1421
Joined: Sat Dec 18, 2004 8:42 am
Location: Passau, Germany
Contact:

coding style

Post by gyboth »

i'd like to adapt for the 1.9 branch the GTK and GLib custom of writing structs and data types capitalized LikeThisIsWritten, and functions, variables and struct members underscore-separated and lower case, like_this_is_written.

this makes the code a bit more readable. if you hack around in 1.9, please try to adhere to this custom. e.g., geovah has a variable named teamID in his season objective patch, which would violate the custom; this isn't important in 1.7, but let's do it in 1.9.

in case you have even better suggestions on style, let me know :-)

gyözö
Press any key to continue or any other key to quit.
gyboth
Site Admin
Posts: 1421
Joined: Sat Dec 18, 2004 8:42 am
Location: Passau, Germany
Contact:

structs

Post by gyboth »

i've also just found out that there's a shorter way to define handy structs. instead of

Code: Select all

typedef struct _Cup Cup;
struct _Cup
{
       gint id;
       ...
};
i can write

Code: Select all

typedef struct {
       gint id;
       ...
} Cup; 
no doubt geovah already knew this but didn't bother to tell me :roll: :evil: :-P

gyözö
Press any key to continue or any other key to quit.
Guest

Re: structs

Post by Guest »

gyboth wrote:i've also just found out that there's a shorter way to define handy structs. instead of

Code: Select all

typedef struct _Cup Cup;
struct _Cup
{
       gint id;
       ...
};
i can write

Code: Select all

typedef struct {
       gint id;
       ...
} Cup; 
no doubt geovah already knew this but didn't bother to tell me :roll: :evil: :-P

gyözö
Because there is some advantage to use the first (can't find good information/documentation about it on internet).

So this is an example :

Code: Select all

 file toto.h
typedef struct _info toto;

void dummy1(toto * dummy); 
toto * dummy2(int dummy);

and

Code: Select all

 file toto.c

struct _info {
	int one;
};

	
void dummy1(toto * dummy) {
	printf("%d",dummy->one);
}

toto * dummy2(int dummy) {
	toto*res=malloc(sizeof(struct _info));
	res->one=dummy;
	return res;
}

But yes, in bygfoot doesn't need to use this style. It's mainly use when you need to hide structure information (set write/read C function with FILE*).
Post Reply