• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 02:54
CET 08:54
KST 16:54
  • 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
RSL Revival - 2025 Season Finals Preview5RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
RSL Revival - 2025 Season Finals Preview Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle 2025 RSL Offline Finals Dates + Ticket Sales! Sparkling Tuna Cup - Weekly Open Tournament StarCraft2.fi 15th Anniversary Cup
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BGH Auto Balance -> http://bghmmr.eu/ [BSL21] RO8 Bracket & Prediction Contest BW General Discussion Let's talk about Metropolis
Tourneys
[ASL20] Grand Finals [BSL21] RO8 - Day 2 - Sunday 21:00 CET [BSL21] RO8 - Day 1 - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates Current Meta Game Theory for Starcraft
Other Games
General Games
Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread Awesome Games Done Quick 2026! Nintendo Switch Thread
Dota 2
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 Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread European Politico-economics QA Mega-thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream?
Blogs
How Sleep Deprivation Affect…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 820 users

The Big Programming Thread - Page 642

Forum Index > General Forum
Post a Reply
Prev 1 640 641 642 643 644 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.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
June 15 2015 14:23 GMT
#12821
On June 15 2015 22:40 BisuDagger wrote:
Show nested quote +
On June 15 2015 22:33 Acrofales wrote:
On June 15 2015 22:11 BisuDagger wrote:
On June 15 2015 22:07 inn5013orecl wrote:
On June 15 2015 21:05 BisuDagger wrote:
Okay this is a pretty odd question and either there is no answer or it is stupidly obvious. Reply in terms of C++, C# please:

If I have a function OnMouseDown() and it calls a function IsUISelected() such that it looks like this:


void OnMouseDown()
{
IsUISelected();
}


If IsUISelected resolves to true in it's function I need to break out out of the OnMouseDown() function instead of continuing.

I'm trying to simply this statement. Simplying the state is purely just a curiosity not a necessity.

void OnMouseDown()
{
if (GlobalVariables.UISelected())
{
return;
}

}






Pretty sure that's as simple as you're going to get. Return pass control back to the caller of OnMouseDown(), effectively exiting out of the function. In this case, works exactly like a break statement in a loop.


void OnMouseDown()
{
if(IsUISelected()) // IsUISelected() value returned
return;
}

That's what I thought. I just have to use this check in so many damn places I was trying to save white space. Oh well lol.

edit: The reason I keep the brackets is to match a coding standard of another companies programmers I have to work with from time to time.

Restructure your program to require less of these checks? Or suck it up. Honestly, I can't think why you wouldn't just put all of that check and return statement on a single line (including {}s). Hell, you can add a line of commentary above it and still save 2 lines if you do it that way.

//Break out of mouse handler if UI is selected
if(IsUISelected()) { return; }


is imho just as clear as the 4-line version (although the line of commentary is not necessary at all, the line is pretty self-explanatory. Better commentary would be a reminder why breaking out of the mouse handler is the proper functioning of the program).

As I mentioned in my edit. For at least this project I'm matching a coding standard for another company. I'm the lead programmer within my company and I 100% agree with you, but the other companies guidelines are "always use brackets for readability" and "Don't comment code unless absolutely necessary to reduce clutter.". I've done really well in my profession by following the technical outlines of a company (even if you disagree) instead of fighting the system.


Yup, no matter how annoying they are, it's important to follow the set coding guidelines. In every company, there are some very annoying rules, e.g. in my last company we had to use an hungarian naming scheme where every object was $objSomething, which was really useless because almost everything was an object, you just didn't know what kind of object. However, in the end it's better to have everyone write code in the same way, even if it has some weird quirks, than have wildly different styles in the same code base. You can slowly change the style guidelines to make exceptions for guard clauses when you have enough influence and support, but until then it's always best to stick to what exists.

Joel Spolsky put it nicely in his article about hungarian notation


When you start out as a beginning programmer or you try to read code in a new language it all looks equally inscrutable. Until you understand the programming language itself you can’t even see obvious syntactic errors.

During the first phase of learning, you start to recognize the things that we usually refer to as “coding style.” So you start to notice code that doesn’t conform to indentation standards and Oddly-Capitalized variables.

It’s at this point you typically say, “Blistering Barnacles, we’ve got to get some consistent coding conventions around here!” and you spend the next day writing up coding conventions for your team and the next six days arguing about the One True Brace Style and the next three weeks rewriting old code to conform to the One True Brace Style until a manager catches you and screams at you for wasting time on something that can never make money, and you decide that it’s not really a bad thing to only reformat code when you revisit it, so you have about half of a True Brace Style and pretty soon you forget all about that and then you can start obsessing about something else irrelevant to making money like replacing one kind of string class with another kind of string class.


The code style doesn't really matter as long as it's good, readable code that works, so you might as well stick to the given rules and not waste your time arguing about braces or no braces.
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
Last Edited: 2015-06-16 08:00:00
June 15 2015 21:06 GMT
#12822
Does anyone here have any experience with QNX embedded systems?
Time is precious. Waste it wisely.
Isualin
Profile Joined March 2011
Germany1903 Posts
June 18 2015 06:44 GMT
#12823
Look at this gem. Maybe we will see an enterprise java application generation simulator someday.
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
necrosexy
Profile Joined March 2011
451 Posts
Last Edited: 2015-06-18 06:55:48
June 18 2015 06:55 GMT
#12824
On June 14 2015 15:11 Frolossus wrote:
Show nested quote +
On June 14 2015 14:28 necrosexy wrote:
any recommended resources for learning unix and shell programming?

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/

On June 14 2015 20:11 Nesserev wrote:
Show nested quote +
On June 14 2015 14:28 necrosexy wrote:
any recommended resources for learning unix and shell programming?

'The Linux Command Line' from No Starch Press, combined with the resource that Frolossus linked above,
will be all you ever need.

Btw, No Starch Press has some of the best and most enjoyable books in the business. Check out their website:
http://www.nostarch.com/

Thanks!!
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-06-18 09:11:17
June 18 2015 09:08 GMT
#12825
@necrosexy:

Also check this guide here out:

http://mywiki.wooledge.org/BashGuide

It has pages that are good to bookmark, for example this here:

http://mywiki.wooledge.org/BashSheet

Depending on what you want to do, one of the pages on that site might be very important to bookmark:

http://mywiki.wooledge.org/Bashism?highlight=(bashism)

The background for what's on that page is: bash is not the default shell on a lot of systems. For Linux, Debian and Ubuntu use something simpler, and what you'll find on for example a router also won't be bash. The BSD's similarly don't use it. So if you write a script targeting the system's /bin/sh, you should be careful to not use features that only work if /bin/sh = bash. How to translate bash to plain sh is what's on that page.
"My goal is to replace my soul with coffee and become immortal."
necrosexy
Profile Joined March 2011
451 Posts
June 19 2015 05:15 GMT
#12826
On June 18 2015 18:08 Ropid wrote:
@necrosexy:

Also check this guide here out:

http://mywiki.wooledge.org/BashGuide

It has pages that are good to bookmark, for example this here:

http://mywiki.wooledge.org/BashSheet

Depending on what you want to do, one of the pages on that site might be very important to bookmark:

http://mywiki.wooledge.org/Bashism?highlight=(bashism)

The background for what's on that page is: bash is not the default shell on a lot of systems. For Linux, Debian and Ubuntu use something simpler, and what you'll find on for example a router also won't be bash. The BSD's similarly don't use it. So if you write a script targeting the system's /bin/sh, you should be careful to not use features that only work if /bin/sh = bash. How to translate bash to plain sh is what's on that page.

i see, thanks!
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
Last Edited: 2015-06-19 22:28:03
June 19 2015 21:24 GMT
#12827
Guys, how do you structure C projects? I've never written anything complex in C before but I plan on changing that and was wondering if there is any kind of "standard" folder structure or anything like that.

I was thinking about something along the lines of this:


/bin
-- executables go here
/config
-- makefiles, misc config files
/data
-- sqlite databases, images etc.
/scripts
-- Lua and other stuff
/src
/ext
-- external libraries (other people's stuff and such)
/lib
-- actual c code goes here
/sys
-- headers go here


Would that be any good? Or should I perhaps keep config, data and scripts inside the src folder?

Edit:

And while we're at it, could anyone help me out a bit with the basic stuff?


#include <stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y));
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y));

// prototypes
int factorial(int n);
int* fill_range(int x, int size);
int* fill_range_reverse(int x, int size);
int* irange(int x, int y);

int main()
{
int fac = factorial(5);
int* range1 = irange(1, 10);
int* range2 = irange(10, 1);
int i = 0;

printf("Factorial of 5 is: %d\n", fac);

for (i = 0; i < 10; ++i)
{
printf("Normal range %d: %d\n", i, range1[i]);
}

for (i = 0; i < 10; ++i)
{
printf("Reverse range %d: %d\n", i, range2[i]);
}

return 0;
}

int factorial(int n)
{
if (n < 2)
return 1;

return (n * factorial(n - 1));
}

int* fill_range(int x, int size)
{
int range[size];
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x += 1;
}

return range;
}

int* fill_range_reverse(int x, int size)
{
int range[size];
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x -= 1;
}

return range;
}

int* irange(int x, int y)
{
int size = MAX(x, y) - MIN(x, y) + 1;

if (x > y)
return fill_range_reverse(x, size);

return fill_range(x, size);
}


                  
main.c: In function 'fill_range':
main.c:54:5: warning: function returns address of local variable [-Wreturn-local-addr]
return range;
^
main.c: In function fill_range_reverse':
main.c:70:5: warning: function returns address of local variable [-Wreturn-local-addr]
return range;
^


I must say that I'm at a loss here... Haven't touched C for years and I pretty much suck hard at it now... I'm too spoiled with new toys to remember exactly how all the static and const stuff worked in C, should I malloc the range initializers first?

Edit2:

Nevermind, sometimes I'm just too dumb...

+ Show Spoiler [fixed code] +


#include <stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y));
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y));

// prototypes
int factorial(int n);
int* fill_range(int x, int size, int* range);
int* fill_range_reverse(int x, int size, int* range);
int* irange(int x, int y);

int main()
{
int fac = factorial(5);
int* range1 = irange(1, 10);
int* range2 = irange(10, 1);
int i = 0;

printf("Factorial of 5 is: %d\n", fac);

for (i = 0; i < 10; ++i)
{
printf("Normal range %d: %d\n", i, range1[i]);
}

for (i = 0; i < 10; ++i)
{
printf("Reverse range %d: %d\n", i, range2[i]);
}

return 0;
}

int factorial(int n)
{
if (n < 2)
return 1;

return (n * factorial(n - 1));
}

int* fill_range(int x, int size, int* range)
{
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x += 1;
}

return range;
}

int* fill_range_reverse(int x, int size, int* range)
{
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x -= 1;
}

return range;
}

int* irange(int x, int y)
{
int size = MAX(x, y) - MIN(x, y) + 1;
int range[size];

if (x > y)
return fill_range_reverse(x, size, range);

return fill_range(x, size, range);
}

Time is precious. Waste it wisely.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2015-06-19 22:32:06
June 19 2015 22:21 GMT
#12828
On June 20 2015 06:24 Manit0u wrote:
Guys, how do you structure C projects? I've never written anything complex in C before but I plan on changing that and was wondering if there is any kind of "standard" folder structure or anything like that.

I was thinking about something along the lines of this:


/bin
-- executables go here
/config
-- makefiles, misc config files
/data
-- sqlite databases, images etc.
/scripts
-- Lua and other stuff
/src
/ext
-- external libraries (other people's stuff and such)
/lib
-- actual c code goes here
/sys
-- headers go here


Would that be any good? Or should I perhaps keep config, data and scripts inside the src folder?


I've got a ton of experience with QNX, though it's been a few years I actually did any projects with it since now I work for a competitor.

That directory structure looks fine, I might put your actual C code in /src, and put external libraries in /lib and headers in /src/include or just /include.
Your Makefile and README should go in the root directory, not /config, but that doesn't mean you shouldn't have a folder for storing random configuration files in it as well, which may include other Makefiles being imported with various compiler options being defined.

Depending on what your project's end output file will be, I prefer to place my project folder within the same folder as the examples for the OS. The benefit is that a lot of your code is going to be copied over from those examples, and that you can put the entire OS in version control along with your project (which you should do, in case you accidentally change something you shouldn't have).

+ Show Spoiler +
If you want to open source your project, don't do this if you had to have a license to decrypt the OS libraries in the first place to install them. If the OS you are using is already open source, consider branching it instead of making a new repository


You'll also need a obj/ folder for storing intermediate object files.

For those who missed the change in his code, the warning was because he stored an array on the stack, then returned it, so if the calling function tried to use that array, it could point to completely different data stored on the stack later.
Any sufficiently advanced technology is indistinguishable from magic
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-06-19 22:35:08
June 19 2015 22:33 GMT
#12829
--- Nuked ---
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
June 19 2015 22:35 GMT
#12830
On June 20 2015 07:33 Nesserev wrote:
Well, you're supposed to dynamically allocate the memory for the array.


// creates a local array on the stack
int range[size];

...

return range; // range is "destroyed" at the end of this function :(



// pointer used to point to array
int* d_range;

// create dynamically allocated array on heap
d_range = (int *)malloc(sizeof(int) * size);

...

return d_range;


Who is going to free() that malloc()?

Manit0u's fixed implementation allows the user of the function to allocate the memory where they want, instead of forcing it onto the heap.
Any sufficiently advanced technology is indistinguishable from magic
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
Last Edited: 2015-06-19 22:53:06
June 19 2015 22:35 GMT
#12831
On June 20 2015 07:21 RoyGBiv_13 wrote:
Show nested quote +
On June 20 2015 06:24 Manit0u wrote:
Guys, how do you structure C projects? I've never written anything complex in C before but I plan on changing that and was wondering if there is any kind of "standard" folder structure or anything like that.

I was thinking about something along the lines of this:


/bin
-- executables go here
/config
-- makefiles, misc config files
/data
-- sqlite databases, images etc.
/scripts
-- Lua and other stuff
/src
/ext
-- external libraries (other people's stuff and such)
/lib
-- actual c code goes here
/sys
-- headers go here


Would that be any good? Or should I perhaps keep config, data and scripts inside the src folder?


I've got a ton of experience with QNX, though it's been a few years I actually did any projects with it since now I work for a competitor.

That directory structure looks fine, I might put your actual C code in /src, and put external libraries in /lib and headers in /src/include or just /include.
Your Makefile and README should go in the root directory, not /config, but that doesn't mean you shouldn't have a folder for storing random configuration files in it as well, which may include other Makefiles being imported with various compiler options being defined.

Depending on what your project's end output file will be, I prefer to place my project folder within the same folder as the examples for the OS. The benefit is that a lot of your code is going to be copied over from those examples, and that you can put the entire OS in version control along with your project (which you should do, in case you accidentally change something you shouldn't have).

+ Show Spoiler +
If you want to open source your project, don't do this if you had to have a license to decrypt the OS libraries in the first place to install them. If the OS you are using is already open source, consider branching it instead of making a new repository


You'll also need a obj/ folder for storing intermediate object files.


With the structure I wasn't asking about QNX specifically. I'm just toying around with ANSI C in my leisure time.

I was asking about QNX because a friend of mine asked me for help and I simply can't refuse stuff that involves learning some new code. The task at hand was relatively simple but I've found QNX's online documentation to be pretty lacking (as in, requiring you to have really good knowledge of the system to understand it, at which point you probably don't need it). I also hat it when they always seem to do for( ; ; ) instead of while(true) or something. But I digress...

The problem he had to solve was the password/pin thingie. Where you give the user a message, wait 5 seconds for input and reset ad infinitum. The task specifically asked to use the alarm() function. While making a simple loop and doing alarm(5) inside of it is easy, actually handling the alarm is not. From what I read in the docs, when the time for the alarm elapses, it sends the SIGALRM which kills the current process, thus exiting the loop and all. I've read that you should handle this signal with sigaction() or somesuch but I couldn't really find a way to make sigaction() resume/restart the loop.

Could you shed some light on the matter?

On June 20 2015 07:35 RoyGBiv_13 wrote:
Manit0u's fixed implementation allows the user of the function to allocate the memory where they want, instead of forcing it onto the heap.


Is it a bad thing?

Edit:

Also, the code purist in my heart tells me to refactor the code, remove fill_range_reverse and simply pass another argument to the fill range function (a boolean) that controls incrementation/decrementation inside of the loop to remove code duplication.

+ Show Spoiler [like so] +


#include <stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y));
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y));

// prototypes
int factorial(int n);
int sum(int n);
int check_increment(int x, int reverse)
int* fill_range(int x, int size, int* range, int reverse);
int* irange(int x, int y);

int main()
{
int fac = factorial(5);
int* range1 = irange(1, 10);
int* range2 = irange(10, 1);
int i = 0;

printf("Factorial of 5 is: %d\n", fac);

for (i = 0; i < 10; ++i)
{
printf("Normal range %d: %d\n", i, range1[i]);
}

for (i = 0; i < 10; ++i)
{
printf("Reverse range %d: %d\n", i, range2[i]);
}

return 0;
}

int factorial(int n)
{
if (n < 2)
return 1;

return (n * factorial(n - 1));
}

int sum(int n)
{
return ((n * (n + 1)) / 2);
}

int check_increment(int x, int reverse)
{
return reverse ? x -= 1 : x += 1;
}

int* fill_range(int x, int size, int* range, int reverse)
{
int i = 0;

while (i < size)
{
range[i] = x;

i += 1;
x = check_increment(x, reverse);
}

return range;
}


int* irange(int x, int y)
{
int size = MAX(x, y) - MIN(x, y) + 1;
int range[size];

return x > ? fill_range(x, size, range, 1) : fill_range(x, size, range, 0);
}

Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-06-19 22:39:31
June 19 2015 22:38 GMT
#12832
--- Nuked ---
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2015-06-19 22:47:35
June 19 2015 22:46 GMT
#12833
On June 20 2015 07:35 Manit0u wrote:
Show nested quote +
On June 20 2015 07:21 RoyGBiv_13 wrote:
On June 20 2015 06:24 Manit0u wrote:
Guys, how do you structure C projects? I've never written anything complex in C before but I plan on changing that and was wondering if there is any kind of "standard" folder structure or anything like that.

I was thinking about something along the lines of this:


/bin
-- executables go here
/config
-- makefiles, misc config files
/data
-- sqlite databases, images etc.
/scripts
-- Lua and other stuff
/src
/ext
-- external libraries (other people's stuff and such)
/lib
-- actual c code goes here
/sys
-- headers go here


Would that be any good? Or should I perhaps keep config, data and scripts inside the src folder?


I've got a ton of experience with QNX, though it's been a few years I actually did any projects with it since now I work for a competitor.

That directory structure looks fine, I might put your actual C code in /src, and put external libraries in /lib and headers in /src/include or just /include.
Your Makefile and README should go in the root directory, not /config, but that doesn't mean you shouldn't have a folder for storing random configuration files in it as well, which may include other Makefiles being imported with various compiler options being defined.

Depending on what your project's end output file will be, I prefer to place my project folder within the same folder as the examples for the OS. The benefit is that a lot of your code is going to be copied over from those examples, and that you can put the entire OS in version control along with your project (which you should do, in case you accidentally change something you shouldn't have).

+ Show Spoiler +
If you want to open source your project, don't do this if you had to have a license to decrypt the OS libraries in the first place to install them. If the OS you are using is already open source, consider branching it instead of making a new repository


You'll also need a obj/ folder for storing intermediate object files.


With the structure I wasn't asking about QNX specifically. I'm just toying around with ANSI C in my leisure time.

I was asking about QNX because a friend of mine asked me for help and I simply can't refuse stuff that involves learning some new code. The task at hand was relatively simple but I've found QNX's online documentation to be pretty lacking (as in, requiring you to have really good knowledge of the system to understand it, at which point you probably don't need it). I also hat it when they always seem to do for(; instead of while(true) or something. But I digress...

The problem he had to solve was the password/pin thingie. Where you give the user a message, wait 5 seconds for input and reset ad infinitum. The task specifically asked to use the alarm() function. While making a simple loop and doing alarm(5) inside of it is easy, actually handling the alarm is not. From what I read in the docs, when the time for the alarm elapses, it sends the SIGALRM which kills the current process, thus exiting the loop and all. I've read that you should handle this signal with sigaction() or somesuch but I couldn't really find a way to make sigaction() resume/restart the loop.

Could you shed some light on the matter?


Hmm, this is actually closer to pure POSIX than anything QNX related, so you're in luck because the documentation for that is actually really well filled out (but never in one place).

Signals won't actually kill the process, it will continue to run after handling the signal, so if you're already in an infinite spin loop, you won't get out of it. Instead, have the signal modify a global variable that the spin loop is based off of (instead of while(true), use while(spinning), where spinning is volatile) http://stackoverflow.com/questions/14042647/using-sigaction-and-alarm-to-break-from-infinite-loop


Any sufficiently advanced technology is indistinguishable from magic
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
June 19 2015 22:56 GMT
#12834
Thanks, that helps a ton.
Time is precious. Waste it wisely.
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
June 19 2015 23:10 GMT
#12835
That fixed code still has the exact same bug btw, just expertly hidden from the compiler.
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
June 19 2015 23:20 GMT
#12836
On June 20 2015 08:10 iaretehnoob wrote:
That fixed code still has the exact same bug btw, just expertly hidden from the compiler.


Which bug?
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
June 19 2015 23:40 GMT
#12837
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
Last Edited: 2015-06-19 23:57:45
June 19 2015 23:42 GMT
#12838
And how should I remedy this?

Edit:

Nevermind. I see my error. I'll think how to solve this.

Edit2:

Should I declare range as global variable, malloc it inside the irange function and free it after use? I was kind of hoping I could avoid declaring globals or assigning array size before calling the irange
Time is precious. Waste it wisely.
Ropid
Profile Joined March 2009
Germany3557 Posts
June 20 2015 10:30 GMT
#12839
You could use malloc() in irange() to create your int[] range on the heap instead of the stack, then perhaps rename irange() to alloc_irange() to make it clear that the user of this function has to free() the buffer in the future.

Or you could put the malloc() in main(), so that it's in the same block of your code where you'll also have to do the free(). In that case you might want to have some sort of info function that calculates the required size to use with malloc() for certain x, y values.
"My goal is to replace my soul with coffee and become immortal."
Manit0u
Profile Blog Joined August 2004
Poland17522 Posts
Last Edited: 2015-06-20 11:07:28
June 20 2015 11:07 GMT
#12840
And what if I put range and other stuff into a struct? Would that be a good idea?

Somehow I completely forgot about structs...
Time is precious. Waste it wisely.
Prev 1 640 641 642 643 644 1032 Next
Please log in or register to reply.
Live Events Refresh
RSL Revival
04:30
Last Chance Qualifier
Crank 1074
Tasteless959
RotterdaM420
IndyStarCraft 126
CranKy Ducklings98
3DClanTV 79
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Crank 1074
Tasteless 959
WinterStarcraft611
RotterdaM 420
IndyStarCraft 126
StarCraft: Brood War
Killer 2293
actioN 743
Hyun 417
Stork 358
910 222
Leta 175
Sacsri 98
sorry 56
soO 51
Movie 41
[ Show more ]
Mind 36
Bale 23
NotJumperer 18
Dewaltoss 12
League of Legends
JimRising 590
C9.Mang0400
Other Games
summit1g10034
XaKoH 143
Happy141
Mew2King69
ViBE46
Livibee38
Trikslyr27
Organizations
Other Games
gamesdonequick685
StarCraft: Brood War
lovetv 10
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH148
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt447
• HappyZerGling134
Upcoming Events
StarCraft2.fi
2h 6m
IPSL
9h 6m
Sziky vs JDConan
OSC
9h 6m
Solar vs Percival
Gerald vs Nicoract
Creator vs ByuN
BSL 21
12h 6m
Sziky vs StRyKeR
Hawk vs Dewalt
RSL Revival
20h 36m
Classic vs TBD
herO vs Zoun
WardiTV 2025
1d 5h
herO vs ShoWTimE
SHIN vs herO
Clem vs herO
SHIN vs Clem
SHIN vs ShoWTimE
Clem vs ShoWTimE
IPSL
1d 9h
Tarson vs DragOn
BSL 21
1d 12h
Tech vs Cross
Bonyth vs eOnzErG
Replay Cast
2 days
Wardi Open
2 days
[ Show More ]
Monday Night Weeklies
2 days
Sparkling Tuna Cup
3 days
Replay Cast
4 days
The PondCast
5 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
RSL Offline Finals
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.