• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:42
CEST 09:42
KST 16:42
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22
Community News
Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event11Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced9
StarCraft 2
General
Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Team Liquid Map Contest #22 - The Finalists
Tourneys
RSL Revival: Season 5 - Qualifiers and Main Event StarCraft Evolution League (SC Evo Biweekly) 2026 GSL Season 2 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament $1,400 SEL Season 3 Ladder Invitational
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
Using AI to optimize marketing campaigns [ASL21] Ro8 Preview Pt2: Progenitors ASL21 General Discussion Why there arent any 256x256 pro maps? BW General Discussion
Tourneys
[ASL21] Ro8 Day 4 [ASL21] Ro8 Day 3 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV OutLive 25 (RTS Game) Daigo vs Menard Best of 10 Nintendo Switch Thread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1152 users

The Big Programming Thread - Page 536

Forum Index > General Forum
Post a Reply
Prev 1 534 535 536 537 538 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
bangsholt
Profile Joined June 2011
Denmark138 Posts
October 26 2014 11:06 GMT
#10701
On October 26 2014 19:55 Cynry wrote:
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.


Logically it makes sense, I'll give you that, but, the only reason to start doing this address of index 0 of str business is, if you want to skip characters in general - otherwise, just pass the pointer. Makes for easier code to understand and test.

On October 26 2014 19:55 Cynry wrote:
Show nested quote +
And here is a case of an array not being the same as a pointer.

One way to view the use of a string literal, is that it will be expanded into something like this

char[6] str = {'h', 'e', 'l', 'l', 'o', '\0'};



That's where your char[6] comes from.

Why do you think that where the while loop stop holds any significance?


I misinterpreted the error. Thought that char[6] pointed to the 7th character (starting at char[0]) and that the while loop was responsible for the error, trying to go too far or something like that (would have been another segfault I guess).
Now if I understand correctly, char[6] simply is an array of 6 char, \0 included, and the error comes from the fact that ft_strclr returns a char *. Correct ?


Yes - you can't assign a pointer to a char (char *) to a char[6] as the error states ;o)

(Unless you do evil things... Don't do evil things!)
Cynry
Profile Blog Joined August 2010
810 Posts
October 26 2014 11:16 GMT
#10702
On October 26 2014 20:06 bangsholt wrote:
Show nested quote +
On October 26 2014 19:55 Cynry wrote:
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.


Logically it makes sense, I'll give you that, but, the only reason to start doing this address of index 0 of str business is, if you want to skip characters in general - otherwise, just pass the pointer. Makes for easier code to understand and test.


But then I'd be back in square one with the segfault, wouldn't I ?
bangsholt
Profile Joined June 2011
Denmark138 Posts
October 26 2014 11:42 GMT
#10703
On October 26 2014 20:16 Cynry wrote:
Show nested quote +
On October 26 2014 20:06 bangsholt wrote:
On October 26 2014 19:55 Cynry wrote:
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.


Logically it makes sense, I'll give you that, but, the only reason to start doing this address of index 0 of str business is, if you want to skip characters in general - otherwise, just pass the pointer. Makes for easier code to understand and test.


But then I'd be back in square one with the segfault, wouldn't I ?


No, because you've changed the way that the "string" is allocated. Before it was put into the read-only section of the binary, which is... read-only and therefore not modifiable.

Now it's in a stack variable instead - basically, by using

char * str = "hello";


You're telling the compiler that you will not modify it, and therefore the compiler can put it into read-only.

By instead doing

char str[] = "hello";


You're telling the compiler that you might want to modify it. The string will most likely still be stored in the read-only, but it will now be copied into a stack variable so that you can modify it, if you want to.
Cynry
Profile Blog Joined August 2010
810 Posts
October 26 2014 11:44 GMT
#10704
Oooh ok. I understood what you said the first time, but didn't realise that once declared that way, I could still use the pointer syntax when passing str to the function. Many thanks for your time and patience !
bangsholt
Profile Joined June 2011
Denmark138 Posts
October 26 2014 11:53 GMT
#10705
On October 26 2014 20:44 Cynry wrote:
Oooh ok. I understood what you said the first time, but didn't realise that once declared that way, I could still use the pointer syntax when passing str to the function. Many thanks for your time and patience !


You're welcome =)
Manit0u
Profile Blog Joined August 2004
Poland17743 Posts
Last Edited: 2014-10-26 12:06:25
October 26 2014 12:02 GMT
#10706
On October 26 2014 19:55 Cynry wrote:
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.

Show nested quote +
And here is a case of an array not being the same as a pointer.

One way to view the use of a string literal, is that it will be expanded into something like this

char[6] str = {'h', 'e', 'l', 'l', 'o', '\0'};



That's where your char[6] comes from.

Why do you think that where the while loop stop holds any significance?


I misinterpreted the error. Thought that char[6] pointed to the 7th character (starting at char[0]) and that the while loop was responsible for the error, trying to go too far or something like that (would have been another segfault I guess).
Now if I understand correctly, char[6] simply is an array of 6 char, \0 included, and the error comes from the fact that ft_strclr returns a char *. Correct ?


str[6] would point to the 7th character, char[6] is a type. You might want to perhaps make some more descriptive variable names, this way you won't confuse them with other things while reading error messages.
Time is precious. Waste it wisely.
Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-10-26 12:32:29
October 26 2014 12:31 GMT
#10707
On October 26 2014 21:02 Manit0u wrote:
Show nested quote +
On October 26 2014 19:55 Cynry wrote:
I thought that
char   str[] = "hello";

ft_strclr(&str[0]);


would be equivalent to
char   *str = "hello";

ft_strclr(str);

would be the same except that I would be able to modifiy the string in the first exemple, avoiding the error that brought me here in the first place because of the second exemple.

And here is a case of an array not being the same as a pointer.

One way to view the use of a string literal, is that it will be expanded into something like this

char[6] str = {'h', 'e', 'l', 'l', 'o', '\0'};



That's where your char[6] comes from.

Why do you think that where the while loop stop holds any significance?


I misinterpreted the error. Thought that char[6] pointed to the 7th character (starting at char[0]) and that the while loop was responsible for the error, trying to go too far or something like that (would have been another segfault I guess).
Now if I understand correctly, char[6] simply is an array of 6 char, \0 included, and the error comes from the fact that ft_strclr returns a char *. Correct ?


str[6] would point to the 7th character, char[6] is a type. You might want to perhaps make some more descriptive variable names, this way you won't confuse them with other things while reading error messages.

Well, to be honest, as much as your advice is sound, this was pure stupidity on my end. There were no variable named char in my code, should have been obvious... Thanks anyway
Manit0u
Profile Blog Joined August 2004
Poland17743 Posts
Last Edited: 2014-10-26 12:46:43
October 26 2014 12:46 GMT
#10708
That's how I learned to stop using variable names like "str", "arr" etc.

And it's still oh so tempting...
Time is precious. Waste it wisely.
Cynry
Profile Blog Joined August 2010
810 Posts
October 26 2014 13:09 GMT
#10709
On October 26 2014 21:46 Manit0u wrote:
That's how I learned to stop using variable names like "str", "arr" etc.

And it's still oh so tempting...

Haha, a good programmer is a lazy one they said, I guess the saying has its limits ^^
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
October 26 2014 13:10 GMT
#10710
reading vague variables from another person's code can kill a man
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 26 2014 13:16 GMT
#10711
On October 26 2014 22:09 Cynry wrote:
Show nested quote +
On October 26 2014 21:46 Manit0u wrote:
That's how I learned to stop using variable names like "str", "arr" etc.

And it's still oh so tempting...

Haha, a good programmer is a lazy one they said, I guess the saying has its limits ^^

Actually that's still true for variable names. Choose them wisely now and save yourself hours later on when you have to change/fix the code. Being lazy doesn't imply being shortsighted.
If you have a good reason to disagree with the above, please tell me. Thank you.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2014-10-26 13:21:23
October 26 2014 13:20 GMT
#10712
You haven't really worked with legacy code if you haven't had to fix code containing variables called "temp" that were reused 5 times in the same block of code and contained crucial data at various points.

My favorite line of code concerning variable names was still:

global $allowASDFXYZ1234 // IMPORTANT: Do not delete
Manit0u
Profile Blog Joined August 2004
Poland17743 Posts
Last Edited: 2014-10-26 14:27:41
October 26 2014 14:23 GMT
#10713
On October 26 2014 22:20 Morfildur wrote:
You haven't really worked with legacy code if you haven't had to fix code containing variables called "temp" that were reused 5 times in the same block of code and contained crucial data at various points.

My favorite line of code concerning variable names was still:

global $allowASDFXYZ1234 // IMPORTANT: Do not delete


At least that's a pretty unique name. I was once updating some really bad code written 20 years ago with a lot of variables named a, b, c and so forth... Trying to find all occurrences of a given variable was a lot of pain, especially that there were hundreds of functions in each file and many were reusing those variable names.

What made it a bit easier was the fact that I could simply delete 70% of the code since it was using deprecated methods that were made obsolete 10 years prior to me working on it.
Time is precious. Waste it wisely.
Cynry
Profile Blog Joined August 2010
810 Posts
October 26 2014 14:33 GMT
#10714
On October 26 2014 22:16 spinesheath wrote:
Show nested quote +
On October 26 2014 22:09 Cynry wrote:
On October 26 2014 21:46 Manit0u wrote:
That's how I learned to stop using variable names like "str", "arr" etc.

And it's still oh so tempting...

Haha, a good programmer is a lazy one they said, I guess the saying has its limits ^^

Actually that's still true for variable names. Choose them wisely now and save yourself hours later on when you have to change/fix the code. Being lazy doesn't imply being shortsighted.

Very good point !

Just wondering, is there any standard concerning variable naming ? Or some sort of guideline, compendium of common sense, anything that I could try to apply in my early coder life ?
Coding standards in my school strongly encourage using explicit names, unfortunately it's not enforced. As I'll have to correct and be corrected by our peers, I'd rather start coding in a readable manner from the get go. And if it's something that I can share with said peers, all the better.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 26 2014 15:23 GMT
#10715
On October 26 2014 23:23 Manit0u wrote:
Show nested quote +
On October 26 2014 22:20 Morfildur wrote:
You haven't really worked with legacy code if you haven't had to fix code containing variables called "temp" that were reused 5 times in the same block of code and contained crucial data at various points.

My favorite line of code concerning variable names was still:

global $allowASDFXYZ1234 // IMPORTANT: Do not delete


At least that's a pretty unique name. I was once updating some really bad code written 20 years ago with a lot of variables named a, b, c and so forth... Trying to find all occurrences of a given variable was a lot of pain, especially that there were hundreds of functions in each file and many were reusing those variable names.

What made it a bit easier was the fact that I could simply delete 70% of the code since it was using deprecated methods that were made obsolete 10 years prior to me working on it.

No syntax-aware search? Or whatever you'd call that.

As for naming guidelines... Do you need a comment or read more than a single line of code to make it clear what the variable does? Then it's named badly.
If you have a good reason to disagree with the above, please tell me. Thank you.
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
October 26 2014 15:31 GMT
#10716
the real question is why the school forbids for loops but allows while loops.
At least they should be consistently retarded and force goto.
dae
Profile Joined June 2010
Canada1600 Posts
October 26 2014 15:41 GMT
#10717
On October 26 2014 23:33 Cynry wrote:
Show nested quote +
On October 26 2014 22:16 spinesheath wrote:
On October 26 2014 22:09 Cynry wrote:
On October 26 2014 21:46 Manit0u wrote:
That's how I learned to stop using variable names like "str", "arr" etc.

And it's still oh so tempting...

Haha, a good programmer is a lazy one they said, I guess the saying has its limits ^^

Actually that's still true for variable names. Choose them wisely now and save yourself hours later on when you have to change/fix the code. Being lazy doesn't imply being shortsighted.

Very good point !

Just wondering, is there any standard concerning variable naming ? Or some sort of guideline, compendium of common sense, anything that I could try to apply in my early coder life ?
Coding standards in my school strongly encourage using explicit names, unfortunately it's not enforced. As I'll have to correct and be corrected by our peers, I'd rather start coding in a readable manner from the get go. And if it's something that I can share with said peers, all the better.


If it is code that only really you, or you and one other person will ever read/have to make sense of, name it whatever you want (1 character names are for the lazy).

If it is code that will have to be maintained for a long time, it should be 100% clear what the variable is/does by the name.

http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Naming is a reference that will do you well to follow.
LaNague
Profile Blog Joined April 2010
Germany9118 Posts
October 26 2014 15:52 GMT
#10718
you never know how long you need the code or how many people will need to read it.


Cynry
Profile Blog Joined August 2010
810 Posts
Last Edited: 2014-10-26 17:19:59
October 26 2014 16:57 GMT
#10719
On October 27 2014 00:31 LaNague wrote:
the real question is why the school forbids for loops but allows while loops.
At least they should be consistently retarded and force goto.

To quote them about the for/while : "it landed on tail." Yup. Goto is forbidden too. If I can get a hold on an english version of the school standard's, I'll post them here, it should give you guys a good laugh.

Edit : Doesn't seem to exist, so here are the good bits :
No more than 25 lines per functions, excluding the starting and ending {}.
No more than 80 characters per line. A tabulation is 4 characters.
1 instruction per line.
1 variable declaration per line.
No declaration and instanciation (? not sure about the english translation) on the same line.
Declarations are to be placed at the beginning of functions.

No more than 4 parameters per functions.
No more than 5 variables declared per functions.

For, do...while, switch, case, goto are forbidden.

No more than 5 functions per .c

No wildcards in Makefiles.


These are the ones that seems the most restricting to me. There's plenty of stuff outside of how we should write our code that is equally as fun as those...

Still, this method has been in use for many years in one of the best french programming school (epitech), so I wouldn't label that as retarded straight away. It's definitely different, but it's exactly what they were aiming for... And for a complete beginner like me (and many other students), it's not that bad.

As for the gotos, if I understood correctly, we'll get plenty of that when we'll use the Assembly langage...


To the one that gave a link to some naming standards, thank you !
Manit0u
Profile Blog Joined August 2004
Poland17743 Posts
Last Edited: 2014-10-26 17:02:16
October 26 2014 16:59 GMT
#10720
I was once working with someone else's code. His variable naming was very helpful and consistent (even more helpful than good names). Every input and output was in the name, so was the variable type (e. g. "s_somestring_in", "i_someint_out", "f_somefloat" - variable with local scope that's neither function param nor is return value etc.). Makes it really easy to follow, the only problem is when you want to change the variable type, as you then have to rename all occurances.

Was nice to work with it since at all times you knew exactly if you're dealing with variable that has been passed to the function, a variable that will be returned or something temporary.
Time is precious. Waste it wisely.
Prev 1 534 535 536 537 538 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 18m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 142
StarCraft: Brood War
Sea 3592
Killer 263
Aegong 80
Mind 76
scan(afreeca) 51
910 50
Shinee 47
Dewaltoss 39
Hyuk 25
ZergMaN 20
[ Show more ]
NotJumperer 10
Bale 9
League of Legends
JimRising 601
Super Smash Bros
Mew2King84
Other Games
summit1g7064
ceh9514
C9.Mang0407
Happy277
monkeys_forever170
NeuroSwarm62
Organizations
Other Games
gamesdonequick763
Dota 2
PGL Dota 2 - Main Stream44
StarCraft: Brood War
lovetv 13
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• LUISG 4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1566
• TFBlade921
• Stunt530
Upcoming Events
Sparkling Tuna Cup
2h 18m
Afreeca Starleague
2h 18m
Snow vs Flash
WardiTV Invitational
3h 18m
SHIN vs Nicoract
Solar vs Nice
PiGosaur Cup
16h 18m
GSL
1d 1h
Classic vs Cure
Maru vs Rogue
GSL
2 days
SHIN vs Zoun
ByuN vs herO
OSC
2 days
OSC
2 days
Replay Cast
2 days
Escore
3 days
[ Show More ]
The PondCast
3 days
WardiTV Invitational
3 days
Zoun vs Ryung
Lambo vs ShoWTimE
OSC
3 days
Replay Cast
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
4 days
Krystianer vs TriGGeR
Cure vs Rogue
uThermal 2v2 Circuit
4 days
BSL
4 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
5 days
BSL
5 days
GSL
6 days
Afreeca Starleague
6 days
Liquipedia Results

Completed

Proleague 2026-05-02
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

YSL S3
Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.