• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:22
CEST 08:22
KST 15:22
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)12Reynor: GSL Loss Wasn't About Preparation Format13[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken? 5.0.16 patch for SC2 goes live (8 worker start) BGE Stara Zagora to be held again in June 2025
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Etiquete rules in Asl? Recommended FPV games (post-KeSPA) Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) BGH Auto Balance -> http://bghmmr.eu/ screpdb: new Starcraft reporting tool
Tourneys
[IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 [Megathread] Daily Proleagues [ASL22] Wildcard Qualifier
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Path of Exile General RTS Discussion Thread Beyond All Reason Nintendo Switch Thread Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8800 users

The Big Programming Thread - Page 403

Forum Index > General Forum
Post a Reply
Prev 1 401 402 403 404 405 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.
Manit0u
Profile Blog Joined August 2004
Poland17792 Posts
November 30 2013 20:41 GMT
#8041
On December 01 2013 05:10 Warri wrote:
Show nested quote +
On December 01 2013 05:00 Manit0u wrote:
On December 01 2013 04:42 Warri wrote:
Woa java is driving me nuts today.
I have this endless loop:

boolean pause=true;
while (true) {
if (!pause) {
update();
}
}

At the start of the program pause is set to true and is not changed in the class which contains the loop. It is only changed in another class, which contains a gui. And heres the weird part: pause gets set to false correctly, but the loop still doesnt run. However, if i add a System.out.println("foo"); inside the loop, it works. So my assumption is, java falsely "optimizes", aka removes, the loop, because the condition is never changed to true inside the class. How can i prevent that without adding dummy commands?


Can you make it more like this?

Class A

while (true) {
if (!ClassB->queryPause(pause)) {
update();
}
}


Class B

boolean pause = true;

... do stuff with pause ...

public boolean queryPause(boolean pause)
{
return pause;
}


I think it would be even better if you had 3 classes. 2 that actually do stuff and have all the data and another one acting as an interface for the other two to communicate. This way you can easily shuffle stuff around and change things later.

Hm i dont understand what the parameter is for in queryPause, if pause is a member of Class B?
I tried this:
Class A:

while (true) {
if (!B.getPause()) {
update();
}
}

Class B:

boolean pause=true;
...
public boolean getPause() {
return pause;
}

This also doesnt work. But again, if i change the getPause() method to

public boolean getPause() {
System.out.println("qwe");
return pause;
}

it starts working... i dont get it


Don't you have to pass the pause variable to getPause method first? I'm a bit confused here and I have no idea why it would suddenly work if you add the print message.
Time is precious. Waste it wisely.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2013-11-30 20:57:22
November 30 2013 20:56 GMT
#8042
That's just weird. o.O

Does it work with other statements in place of the print statement(out of curiosity)? Maybe the return statement just got lonely
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Die4Ever
Profile Joined August 2010
United States17742 Posts
November 30 2013 21:00 GMT
#8043
hi guys, I made the source code public for the WCS Predictor 2014 that I'm currently working on.
http://4ever.tv/wcs_predictor_2014/
Remember this code is made to be optimized so I can run maximum sample sizes, and is not really good coding style usually.
(also I'm in the contest thing please vote for me in Group P http://www.teamliquid.net/forum/viewmessage.php?topic_id=436997)
"Expert" mods4ever.com
Warri
Profile Joined May 2010
Germany3208 Posts
November 30 2013 21:06 GMT
#8044

int i;
public boolean getPause() {
i++;
return pause;
}

doesnt work.


int i;
public boolean getPause() {
System.out.println(i);
return pause;
}

works. As i said, i have absolutely no idea why it does that.
Die4Ever
Profile Joined August 2010
United States17742 Posts
Last Edited: 2013-11-30 21:18:40
November 30 2013 21:12 GMT
#8045
On December 01 2013 06:06 Warri wrote:

int i;
public boolean getPause() {
i++;
return pause;
}

doesnt work.


int i;
public boolean getPause() {
System.out.println(i);
return pause;
}

works. As i said, i have absolutely no idea why it does that.

I'm not experienced in java, but it sounds like a threading issue maybe? If that's the case then what you need is a memory barrier so that java knows to check the ram for the updated value rather than reusing what's in the cpu register, or set the variable to volatile if java has such a thing. The println function would act as memory barrier and that would be why that "fixes" it.

edit: yea java has volatile, this is what you need http://stackoverflow.com/questions/2423622/volatile-vs-static-in-java
"Expert" mods4ever.com
Warri
Profile Joined May 2010
Germany3208 Posts
November 30 2013 21:28 GMT
#8046
On December 01 2013 06:12 Die4Ever wrote:
Show nested quote +
On December 01 2013 06:06 Warri wrote:

int i;
public boolean getPause() {
i++;
return pause;
}

doesnt work.


int i;
public boolean getPause() {
System.out.println(i);
return pause;
}

works. As i said, i have absolutely no idea why it does that.

I'm not experienced in java, but it sounds like a threading issue maybe? If that's the case then what you need is a memory barrier so that java knows to check the ram for the updated value rather than reusing what's in the cpu register, or set the variable to volatile if java has such a thing. The println function would act as memory barrier and that would be why that "fixes" it.

edit: yea java has volatile, this is what you need http://stackoverflow.com/questions/2423622/volatile-vs-static-in-java

Yeah that works, thank you!
Manit0u
Profile Blog Joined August 2004
Poland17792 Posts
Last Edited: 2013-12-01 19:02:58
December 01 2013 17:18 GMT
#8047
On December 01 2013 06:28 Warri wrote:
Show nested quote +
On December 01 2013 06:12 Die4Ever wrote:
On December 01 2013 06:06 Warri wrote:

int i;
public boolean getPause() {
i++;
return pause;
}

doesnt work.


int i;
public boolean getPause() {
System.out.println(i);
return pause;
}

works. As i said, i have absolutely no idea why it does that.

I'm not experienced in java, but it sounds like a threading issue maybe? If that's the case then what you need is a memory barrier so that java knows to check the ram for the updated value rather than reusing what's in the cpu register, or set the variable to volatile if java has such a thing. The println function would act as memory barrier and that would be why that "fixes" it.

edit: yea java has volatile, this is what you need http://stackoverflow.com/questions/2423622/volatile-vs-static-in-java

Yeah that works, thank you!


Could you also check one other way to do it that could possibly fix the issue without the need for volatile types? What happens if you prototype functions that use pause variable? To do that you have to declare the function before you define it, like so:



boolean getPause();

int main()
{
getPause();

return 0;
}

boolean getPause();
{
do_stuff();
}


That is, of course, if Java supports prototypes...

Edit: Scratch that. I read up on that and it seems that Java has method signatures but not method prototypes.
Time is precious. Waste it wisely.
Warri
Profile Joined May 2010
Germany3208 Posts
Last Edited: 2013-12-01 23:43:08
December 01 2013 23:41 GMT
#8048
On December 02 2013 02:18 Manit0u wrote:
Show nested quote +
On December 01 2013 06:28 Warri wrote:
On December 01 2013 06:12 Die4Ever wrote:
On December 01 2013 06:06 Warri wrote:

int i;
public boolean getPause() {
i++;
return pause;
}

doesnt work.


int i;
public boolean getPause() {
System.out.println(i);
return pause;
}

works. As i said, i have absolutely no idea why it does that.

I'm not experienced in java, but it sounds like a threading issue maybe? If that's the case then what you need is a memory barrier so that java knows to check the ram for the updated value rather than reusing what's in the cpu register, or set the variable to volatile if java has such a thing. The println function would act as memory barrier and that would be why that "fixes" it.

edit: yea java has volatile, this is what you need http://stackoverflow.com/questions/2423622/volatile-vs-static-in-java

Yeah that works, thank you!


Could you also check one other way to do it that could possibly fix the issue without the need for volatile types? What happens if you prototype functions that use pause variable? To do that you have to declare the function before you define it, like so:



boolean getPause();

int main()
{
getPause();

return 0;
}

boolean getPause();
{
do_stuff();
}


That is, of course, if Java supports prototypes...

Edit: Scratch that. I read up on that and it seems that Java has method signatures but not method prototypes.

As far as i understand your post, that seems to be what an interface does in java. I dont think that would change anything though :p
http://en.wikipedia.org/wiki/Interface_(Java)#Overview
Specifically "Interface methods are public, abstract and never final. Think of them as prototypes only; no implementations are allowed."
Roe
Profile Blog Joined June 2010
Canada6002 Posts
Last Edited: 2013-12-01 23:44:16
December 01 2013 23:44 GMT
#8049
Hey I just had a quick question about interfaces - why is it useful to use them when you're simply reiterating the definition of a method? Like so:

+ Show Spoiler +
void Update();

void Update()
{
stuff
}


It doesn't seem like you're adding anything to the method you're using by implementing an interface, in fact it seems like you're only adding more code typing to do.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-12-02 00:20:52
December 01 2013 23:56 GMT
#8050
On December 02 2013 08:44 Roe wrote:
Hey I just had a quick question about interfaces - why is it useful to use them when you're simply reiterating the definition of a method? Like so:

+ Show Spoiler +
void Update();

void Update()
{
stuff
}


It doesn't seem like you're adding anything to the method you're using by implementing an interface, in fact it seems like you're only adding more code typing to do.


Sorry, I assumed you mean Java's interfaces. I think I've not come across such a keyword in Objective-C and C, but it's still possible that other languages use the keyword.

In my opinion, interface is like what a contract is. If you inherit the class, then you have to play by the house's rules. Every further implementation of the interface also binds you to that "contract".

I'm not too experienced with Java, so take this with a grain of salt.

Edit #1: As far as I remember, when I was doing Java RMI for university, the client only knows about the interface but not about implementation, so if I'm not mistaken, you can also hide implementation from the user.

Edit #2: Oh, yeah, I just remembered what I've recently studied in Software Engineering.

Basically, if you have an interface:


interface Encryption {
public String encrypt(String);
}


and then:


class LowerLevelEncryption implements Encryption {
// constructor
LowerLevelEncryption() {

}

public String encrypt(String blahblah) {
...
}
}



class HigherLevelEncryption implements Encryption {
// constructor
HigherLevelEncryption() {

}

public String encrypt(String blahblah) {
...
}
}


Now you can take advantage of polymorphism by choosing which encryption level to use at runtime.

E.g.

Encryption encryptionMethod = new HigherLevelEncryption();

and you can change it anytime to: encryptionMethod = new LowerLevelEncryption();
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
December 02 2013 00:07 GMT
#8051
On December 02 2013 08:44 Roe wrote:
Hey I just had a quick question about interfaces - why is it useful to use them when you're simply reiterating the definition of a method? Like so:

+ Show Spoiler +
void Update();

void Update()
{
stuff
}


It doesn't seem like you're adding anything to the method you're using by implementing an interface, in fact it seems like you're only adding more code typing to do.


it's about future updates to the code. maybe there will be new classes to implement that interface later.
And all is illuminated.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2013-12-02 03:10:07
December 02 2013 03:09 GMT
#8052
--- Nuked ---
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2013-12-03 03:29:58
December 03 2013 03:26 GMT
#8053
Hw help:
From a test header file like so:
...
char s[]={"2/3","2/-3"};
...

I need to convert that string into a fraction (int array). The C files utilizes this function (fraction is a struct and all has been initialized):

Fraction string_to_fraction(const char *S)
{
Fraction result = {0,1}; //to initialize
sscanf(S,"%d/%d",result); //to read in the data as int to place into the result array
return result;
}

Am I doing something wrong? This assignment is more of "fill in the blanks" type fyi (standard library, variables initialized etc...) I am not looking for someone to do my hw but simply to point me in the right direction as when I try to execute the program that tests my function it simply crashes with no warning.
wat wat in my pants
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2013-12-03 03:33:37
December 03 2013 03:30 GMT
#8054
Yeah you need to pass in pointers to each element of your fraction. Your fraction has two elements. Your sscanf call would look something more like:

const char *in = "1/2";
int out[2];

sscanf( in, "%d/%d", out, out + 1 );


Edit: Oh you said Fraction is a struct. Okay like this then:

typedef struct Fraction
{
int numerator;
int denominator;
} Fraction;

Fraction f;

const char *stringFraction = "1/2";

sscanf( stringFraction, "%d/%d", &f.numerator, &f.denominator );


Does this make sense?
heroyi
Profile Blog Joined March 2009
United States1064 Posts
December 03 2013 03:37 GMT
#8055
On December 03 2013 12:30 CecilSunkure wrote:
Yeah you need to pass in pointers to each element of your fraction. Your fraction has two elements. Your sscanf call would look something more like:

const char *in = "1/2";
int out[2];

sscanf( in, "%d/%d", out, out + 1 );


Edit: Oh you said Fraction is a struct. Okay like this then:

typedef struct Fraction
{
int numerator;
int denominator;
} Fraction;

Fraction f;

const char *stringFraction = "1/2";

sscanf( stringFraction, "%d/%d", &f.numerator, &f.denominator );


Does this make sense?

yep.

I literally just figured it out after I posted. Your response only solidifies it. Thanks for the quick reply and appreciate the help.
wat wat in my pants
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
December 03 2013 05:47 GMT
#8056
While you're at numerator/denominator, is the alternative String.split() in Java? Just wondering.
Nausea
Profile Joined October 2010
Sweden807 Posts
Last Edited: 2013-12-03 13:50:52
December 03 2013 13:40 GMT
#8057
Ok! So your favorite noob is back with a question for c++.

I have 2 classes, both within the same namespace.
One of the classes calls upon the other with a function and one of the parameters is of the first class.
I try to send it with a "this" pointer and that can't be done because the compiler complains that i try to send namespacename::classname* instead of just the classname*.

I tried adding the namespace to the functions parameter but that didn't work.

Basically:

m_stateMachine.SetState(m_stateFactory->GetState(0), this, 0);

bool CStateMachine::SetState(CState* _state, CGame* _game, unsigned int _id)
Set it ablaze!
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
December 03 2013 14:04 GMT
#8058
What's the actual error message? What's the prototype/signature of m_stateFactory->GetState(0)? And I assume the type of "this" is CGame* ?
Nausea
Profile Joined October 2010
Sweden807 Posts
Last Edited: 2013-12-03 14:10:30
December 03 2013 14:07 GMT
#8059
On December 03 2013 23:04 iaretehnoob wrote:
What's the actual error message? What's the prototype/signature of m_stateFactory->GetState(0)? And I assume the type of "this" is CGame* ?


error C2664: 'tpe::CStateMachine::SetState' : cannot convert parameter 2 from 'tpe::CGame *const ' to 'CGame *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Yes, "this" is CGame*.

And they are both in the tpe namespace.
Set it ablaze!
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
December 03 2013 14:48 GMT
#8060
On December 03 2013 22:40 Nausea wrote:
Ok! So your favorite noob is back with a question for c++.

I have 2 classes, both within the same namespace.
One of the classes calls upon the other with a function and one of the parameters is of the first class.
I try to send it with a "this" pointer and that can't be done because the compiler complains that i try to send namespacename::classname* instead of just the classname*.

I tried adding the namespace to the functions parameter but that didn't work.

Basically:

m_stateMachine.SetState(m_stateFactory->GetState(0), this, 0);

bool CStateMachine::SetState(CState* _state, CGame* _game, unsigned int _id)


Putting this might work:

bool CStateMachine::SetState(CState* _state, CGame* const _game, unsigned int _id)


I believe 'this' is a const pointer that cannot have its address modified.
Prev 1 401 402 403 404 405 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 39m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft787
oGsTOP 121
StarCraft: Brood War
Icarus 18
ajuk12(nOOB) 15
Bale 14
Dota 2
NeuroSwarm148
League of Legends
JimRising 698
Counter-Strike
Coldzera 1222
Other Games
summit1g5527
C9.Mang0291
XaKoH 168
RuFF_SC295
Trikslyr13
Organizations
Other Games
gamesdonequick1771
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH309
• practicex 26
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota283
League of Legends
• Stunt643
Upcoming Events
Replay Cast
2h 39m
CrankTV Team League
4h 39m
WardiTV Qualifier
5h 39m
Epic.LAN
6h 39m
Big Brain Bouts
9h 39m
SHIN vs Elazer
Percival vs Nicoract
Reynor vs Lambo
Replay Cast
17h 39m
RSL Revival
1d 2h
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
1d 3h
Epic.LAN
1d 6h
IPSL
1d 9h
Dragon vs Hawk
[ Show More ]
RSL Revival
2 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
2 days
OSC
2 days
IPSL
2 days
Bonyth vs Ret
WardiTV Weekly
3 days
Monday Night Weeklies
3 days
PiGosaur Cup
4 days
The PondCast
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
Escore Tournament S3: W3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.