Segmentation Fault

P

pembed2012

In that case just rewrite it. That will be more reliable in the long
term. And you can take the opportunity to add some comments.

But you will need a specification, or know how it fits into the bigger
picture. Those hard-coded array bounds are a bit worrying, and confusing
too with one set of arrays having a length of 11, and an upper bound of
10, and another set having a length of 10, and an upper bound of 9...

I will do this if someone can explain me in simple terms what this
function is doing. The documentation just say it implements a work queue,
11 is the max wait.

Also John Gordon is correct that -1 is considered a sentinal value.
However I would like to know exactly what input arrays are acceptable and
lead to no segfault.

Thanks for you're interest.
 
J

James Kuyper

On 05/16/2012 03:56 PM, pembed2012 wrote:
....
I will do this if someone can explain me in simple terms what this
function is doing. The documentation just say it implements a work queue,
11 is the max wait.

You're asking in the wrong place. To get that explanation, you need to
contact someone familiar with this particular function. The person who
wrote the latest version of that function would be best. However, if you
can't reach such a person, then look for somebody who's written code
that calls the routine.

If you replaced the body of the function with { return;}, who would know
that it wasn't working properly? If there's no one who would know, then
you might as well perform the replacement - at least it doesn't
segfault. If there is someone who can tell you that such a replacement
wasn't working properly, that person can also tell you something
important about what "working properly" means for this particular
function. Find that person and ask.
 
I

Ike Naar

if(ctm[qu] == 0);


This statement is redundant (it's an if statement with an
empty body). Elsethread, you say that the code was written
by a "genius programmer" and is super efficient.
Including a redundant statement is not what one would
expect from such a programmer. Is the code that you posted
the real, unmodified code?
 
J

James Kuyper

On 05/16/2012 03:56 PM, pembed2012 wrote:
....
I will do this if someone can explain me in simple terms what this
function is doing. The documentation just say it implements a work queue,
11 is the max wait.

You're asking in the wrong place. To get that explanation, you need to
contact someone familiar with this particular function. The person who
wrote the latest version of that function would be best. However, if you
can't reach such a person, then look for somebody who's written code
that calls the routine.

If you replaced the body of the function with { return;}, who would know
that it wasn't working properly? If there's no one who would know, then
you might as well perform the replacement - at least it doesn't
segfault. If there is someone who can tell you that such a replacement
wasn't working properly, that person can also tell you something
important about what "working properly" means for this particular
function. Find that person and ask.
 
G

Guest

if(ctm[qu] == 0);


This statement is redundant (it's an if statement with an
empty body). Elsethread, you say that the code was written
by a "genius programmer" and is super efficient.
Including a redundant statement is not what one would
expect from such a programmer. Is the code that you posted
the real, unmodified code?


people sometimes mistake "hard to understand and sort of works" for "genius". I used to think every project needed a "hacker" who could produce write-only code astonishingly quickly. If you changed the requirement (or insisted on robustness or deterministic behaviour or something) then he'd throw all his code away and write a new version from scratch, astonishingly quickly..

Then a Real programmer has to take this... stuff ...and turn it into a usable library.
 
I

Ike Naar

if(ctm[qu] == 0);


This statement is redundant (it's an if statement with an
empty body). Elsethread, you say that the code was written
by a "genius programmer" and is super efficient.
Including a redundant statement is not what one would
expect from such a programmer. Is the code that you posted
the real, unmodified code?


people sometimes mistake "hard to understand and sort of works" for
"genius". I used to think every project needed a "hacker" who could
produce write-only code astonishingly quickly. If you changed the
requirement (or insisted on robustness or deterministic behaviour or
something) then he'd throw all his code away and write a new version
from scratch, astonishingly quickly.

Then a Real programmer has to take this... stuff ...and turn it into a
usable library.


The if statement quoted above has an un-hacker-ish smell.
It's not tricky; it's a plain no-op; it wastes cpu time; hackers hate that.
On the other hand it looks very much like an editing error.
That's why I asked if pembed2012 posted the real, unmodified code.
 
P

pembed2012

if(ctm[qu] == 0);


This statement is redundant (it's an if statement with an empty body).
Elsethread, you say that the code was written by a "genius programmer"
and is super efficient. Including a redundant statement is not what one
would expect from such a programmer. Is the code that you posted the
real, unmodified code?


The only thing I can think of is, maybe the condition is being evaluated
for its side effects.

Of course it may be a bug. How does the behavior of the code change if
you delete the ; ?

I don't feel like I've had a clear answer yet about what this function is
doing and how it works!
 
J

James Kuyper

if(ctm[qu] == 0);


This statement is redundant (it's an if statement with an empty body).
Elsethread, you say that the code was written by a "genius programmer"
and is super efficient. Including a redundant statement is not what one
would expect from such a programmer. Is the code that you posted the
real, unmodified code?


The only thing I can think of is, maybe the condition is being evaluated
for its side effects.


Side effects can only result from ++, --, assignment expressions,
certain function calls, or accessing a volatile object. None of those
things happen in this code, so that can't be the reason.
Of course it may be a bug. How does the behavior of the code change if
you delete the ; ?

In the original code, it said:

if(ctm[qu] == 0);
atm[qu] = -1;

That's exactly equivalent to

atm[qu] = -1;

Removing the semicolon would change the code so that it was equivalent to
if(ctm[qu] == 0)
{
atm[qu] = -1;
}

which is very different.
I don't feel like I've had a clear answer yet about what this function is
doing and how it works!

You haven't, because you've been asking the wrong people. Is there
anyone who's ever written code that uses this function that you can talk to?
 
J

Jorgen Grahn

On 05/15/2012 03:27 PM, pembed2012 wrote:
...

Don't give the original author more credit than he deserves.

Agree. A hack who spends months and a lot of effort solving a fairly
easy problem in a complicated way, can to the untrained eye look much
like a genius hacker solving a difficult problem in an acceptable way.
A truly
professional programmer chooses variable names that are helpful, and
creates documentation that is more than minimal, and would use
appropriately named macro(s) rather than hard-coded numbers like 9, 10,
and 11.

/Jorgen
 
I

Ike Naar

I don't feel like I've had a clear answer yet about what this function is
doing and how it works!

I would guess that:
- it's a job scheduler using the "shortest remaining time next" algorithm,
- the input arrays atm and ctm are arrival times and completion times
- the code, as posted, has never worked

If you expect people to spend time to help you, it would be nice if you'd
share all information that you have.
So far, you seem to have been reluctant to do so.

Can you show an example of a call to srtn() ?
Can you post the body of print_report ?
Is the code, as posted, the original code, or have you made
modifications ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top