• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:20
CEST 22:20
KST 05:20
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL49Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Esports World Cup 2025 - Final Player Roster How does the number of casters affect your enjoyment of esports? Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo) FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Flash Announces Hiatus From ASL [ASL19] Finals Recap: Standing Tall BGH Auto Balance -> http://bghmmr.eu/ Player “Jedi” cheat on CSL Help: rep cant save
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Trading/Investing Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread NBA General Discussion Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 660 users

The Big Programming Thread - Page 642

Forum Index > General Forum
Post a Reply
Prev 1 640 641 642 643 644 1031 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
Poland17243 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
Poland17243 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
Poland17243 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
Poland17243 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
Poland17243 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
Poland17243 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
Poland17243 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 40m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 596
JuggernautJason94
StarCraft: Brood War
Britney 14479
Dewaltoss 192
Aegong 45
GoRush 13
IntoTheRainbow 7
yabsab 5
Dota 2
Gorgc7367
League of Legends
Dendi1481
JimRising 443
Counter-Strike
fl0m1928
flusha408
Foxcn365
sgares185
Super Smash Bros
Mew2King179
Heroes of the Storm
Liquid`Hasu605
Other Games
summit1g6033
FrodaN2371
tarik_tv1112
elazer248
RotterdaM161
Pyrionflax116
ViBE84
Trikslyr64
Sick62
PPMD12
Liquid`Ken5
Organizations
Other Games
BasetradeTV30
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• LUISG 10
• intothetv
• IndyKCrew
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• blackmanpl 38
• 80smullet 29
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Doublelift2783
• Jankos2203
• masondota2502
Other Games
• imaqtpie873
• Shiphtur187
Upcoming Events
Replay Cast
3h 40m
RSL Revival
13h 40m
herO vs SHIN
Reynor vs Cure
OSC
16h 40m
WardiTV European League
19h 40m
Scarlett vs Percival
Jumy vs ArT
YoungYakov vs Shameless
uThermal vs Fjant
Nicoract vs goblin
Harstem vs Gerald
FEL
19h 40m
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
RSL Revival
1d 13h
FEL
1d 19h
Sparkling Tuna Cup
2 days
[ Show More ]
RSL Revival
2 days
FEL
2 days
BSL: ProLeague
2 days
Dewalt vs Bonyth
Replay Cast
4 days
Replay Cast
4 days
The PondCast
5 days
Replay Cast
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.