Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411731 Posts in 69403 Topics- by 58455 Members - Latest Member: Sergei

May 22, 2024, 02:10:52 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Coding styles
Pages: 1 ... 5 6 [7]
Print
Author Topic: Coding styles  (Read 18901 times)
skyy
Level 2
**


[ SkyWhy ]


View Profile
« Reply #120 on: March 07, 2010, 10:31:18 AM »

Out of sheer curiosity, why do you use typedef in this situation (HDLIGHT -> HDLIGHT)?
That's my typedef, that's my style Tongue

Cool, this explanation works for me Smiley just wondered was there a special reason behind it.


Quote from: skyy link=topic=11 327.msg350508#msg350508 date=1267963467
Out of sheer curiosity, why do you use typedef in this situation (HDLIGHT -> HDLIGHT)?
It's not HDLIGHT->HDLIGHT, it's struct HDLIGHT->HDLIGHT
What I meant with the (HDLIGHT -> HDLIGHT) was just there to show that why "typedef" from HDLIGHT to HDLIGHT. I'd understand if it was a completely different like typedef HDLIGHT to AwesomeVariable so I thought I'd ask was there some sort of magical thing going on and it was pretty much as I thought it was. A personal preference.
« Last Edit: March 07, 2010, 11:03:53 AM by skyy » Logged

Glaiel-Gamer
Guest
« Reply #121 on: March 07, 2010, 11:13:43 AM »

Quote from: skyy link=topic=11 327.msg350508#msg350508 date=1267963467
Out of sheer curiosity, why do you use typedef in this situation (HDLIGHT -> HDLIGHT)?
It's not HDLIGHT->HDLIGHT, it's struct HDLIGHT->HDLIGHT
What I meant with the (HDLIGHT -> HDLIGHT) was just there to show that why "typedef" from HDLIGHT to HDLIGHT. I'd understand if it was a completely different like typedef HDLIGHT to AwesomeVariable so I thought I'd ask was there some sort of magical thing going on and it was pretty much as I thought it was. A personal preference.

in C, you structs are declared like

struct Point {
float x, y;
};


and you can't create one like

Point p1 = {1, 2};

in C, it has to be declared like

struct Point p1 = {1, 2};

i.e., the NAME of the type is "struct Point", so it was standard practice in C to stick typedef in front so you dont need to type "struct" every time.

(this is unnecessary in c++, but habits dont break easily if you learned on C)
Logged
skyy
Level 2
**


[ SkyWhy ]


View Profile
« Reply #122 on: March 07, 2010, 12:25:03 PM »

loads of stuff I deleted by mistake  Facepalm

Now that I look back, the habbit was hammered into me too when I was doing C at my old polytechnic. Though haven't done C in ages. Been with higher level languages for too long.
Logged

Sos
Level 8
***


I make bad games


View Profile WWW
« Reply #123 on: March 07, 2010, 02:30:23 PM »


a += b;
a *= c;
a %= n;

rather than a = (a+b)*c%n

[...]the second is "faster"[...]

no, it's the same
Logged

Kekskiller
Guest
« Reply #124 on: March 07, 2010, 03:45:43 PM »


a += b;
a *= c;
a %= n;

rather than a = (a+b)*c%n

[...]the second is "faster"[...]

no, it's the same

Stop declaring things without definition.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #125 on: March 07, 2010, 08:23:01 PM »

I always capitalise structs. I don't know if it's a good habit, but i can tell what's struct, and should have a pointer,and what's not and should be plain ol var.

Code:
typedef struct HDLIGHT
{
  int x,y,lit;
  float sine,phase,wave,light,range,theta,d,dx,dy;
} HDLIGHT;

Did you know that you don't need the tag name when you do this?  You can save yourself some typing by reducing it to this:

Code:
typedef struct
{
  int x,y,lit;
  float sine,phase,wave,light,range,theta,d,dx,dy;
} HDLIGHT;
Logged



What would John Carmack do?
Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #126 on: March 08, 2010, 01:30:13 AM »

My biggest beef with C++ is actually not its high level constructs and how they fit together, but rather its low level ones.

Man, I so agree with all that, annoying to no end.
Logged
Pages: 1 ... 5 6 [7]
Print
Jump to:  

Theme orange-lt created by panic