Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.c

Reply
 
Thread Tools Display Modes
  #16 (permalink)  
Old 05-15-2012, 07:56 PM
John Gordon
Guest
 
Posts: n/a
Default Re: Segmentation Fault

In <jouanj$jhq$1@speranza.aioe.org> pembed2012 <once@was.enough.invalid> writes:

> What conditions do I need on atm and ctm when they get passed into ensure
> no segfaults? Basically the function should be doing a kind of job queue,
> I think qu=queue, wt=wait, tarnd=turn-around, wt=wait etc.


I ran a test with atm and ctm set to all -1's, and did not get a segfault.
But I have no idea if those values represent useful data.

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #17 (permalink)  
Old 05-15-2012, 08:10 PM
Kaz Kylheku
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 2012-05-15, pembed2012 <once@was.enough.invalid> wrote:
> The code was by a "genius programmer" who has gone away, his code was
> superefficient but maybe the variable names were not helpful and the
> documentation was minimal :-)


If the code crashes, how do you conclude that it is superefficient?
Reply With Quote
  #18 (permalink)  
Old 05-15-2012, 09:43 PM
lawrence.jones@siemens.com
Guest
 
Posts: n/a
Default Re: Segmentation Fault

Kaz Kylheku <kaz@kylheku.com> wrote:
> On 2012-05-15, pembed2012 <once@was.enough.invalid> wrote:
> > The code was by a "genius programmer" who has gone away, his code was
> > superefficient but maybe the variable names were not helpful and the
> > documentation was minimal :-)

>
> If the code crashes, how do you conclude that it is superefficient?


It crashes really quickly without using much memory or CPU time? :-)
--
Larry Jones

I like maxims that don't encourage behavior modification. -- Calvin
Reply With Quote
  #19 (permalink)  
Old 05-15-2012, 10:27 PM
James Kuyper
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 05/15/2012 05:43 PM, lawrence.jones@siemens.com wrote:
> Kaz Kylheku <kaz@kylheku.com> wrote:
>> On 2012-05-15, pembed2012 <once@was.enough.invalid> wrote:
>>> The code was by a "genius programmer" who has gone away, his code was
>>> superefficient but maybe the variable names were not helpful and the
>>> documentation was minimal :-)

>>
>> If the code crashes, how do you conclude that it is superefficient?

>
> It crashes really quickly without using much memory or CPU time? :-)


Keep in mind that the OP doesn't know how to correctly initialize the
input data. The function could be superefficient when used as intended,
and crash when used in a way that it was not intended to be used.
Reply With Quote
  #20 (permalink)  
Old 05-16-2012, 07:56 PM
pembed2012
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On Tue, 15 May 2012 20:38:05 +0100, BartC wrote:

> "pembed2012" <once@was.enough.invalid> wrote in message
> news:jouanj$jhq$1@speranza.aioe.org...
>
>
>> The code was by a "genius programmer" who has gone away, his code was
>> superefficient but maybe the variable names were not helpful and the
>> documentation was minimal :-)
>>
>> What conditions do I need on atm and ctm when they get passed into
>> ensure no segfaults? Basically the function should be doing a kind of
>> job queue, I think qu=queue, wt=wait, tarnd=turn-around, wt=wait etc.

>
> 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.
Reply With Quote
  #21 (permalink)  
Old 05-16-2012, 08:17 PM
James Kuyper
Guest
 
Posts: n/a
Default Re: Segmentation Fault

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.
Reply With Quote
  #22 (permalink)  
Old 05-16-2012, 08:17 PM
Ike Naar
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 2012-05-14, pembed2012 <once@was.enough.invalid> wrote:
> if(ctm[qu[i]] == 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?
Reply With Quote
  #23 (permalink)  
Old 05-16-2012, 08:17 PM
James Kuyper
Guest
 
Posts: n/a
Default Re: Segmentation Fault

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.
Reply With Quote
  #24 (permalink)  
Old 05-17-2012, 10:05 AM
nick_keighley_nospam@hotmail.com
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On Wednesday, May 16, 2012 9:17:22 PM UTC+1, Ike Naar wrote:
> On 2012-05-14, pembed2012 <once@was.enough.invalid> wrote:


> > if(ctm[qu[i]] == 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.
Reply With Quote
  #25 (permalink)  
Old 05-17-2012, 11:07 AM
Ike Naar
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 2012-05-17, nick_keighley_nospam@hotmail.com wrote:
> On Wednesday, May 16, 2012 9:17:22 PM UTC+1, Ike Naar wrote:
>> On 2012-05-14, pembed2012 <once@was.enough.invalid> wrote:

>
>> > if(ctm[qu[i]] == 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.
Reply With Quote
  #26 (permalink)  
Old 05-17-2012, 07:50 PM
pembed2012
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On Wed, 16 May 2012 20:17:22 +0000, Ike Naar wrote:

> On 2012-05-14, pembed2012 <once@was.enough.invalid> wrote:
>> if(ctm[qu[i]] == 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!
Reply With Quote
  #27 (permalink)  
Old 05-17-2012, 08:59 PM
James Kuyper
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 05/17/2012 03:50 PM, pembed2012 wrote:
> On Wed, 16 May 2012 20:17:22 +0000, Ike Naar wrote:
>
>> On 2012-05-14, pembed2012 <once@was.enough.invalid> wrote:
>>> if(ctm[qu[i]] == 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[i]] == 0);
atm[qu[i]] = -1;

That's exactly equivalent to

atm[qu[i]] = -1;

Removing the semicolon would change the code so that it was equivalent to
if(ctm[qu[i]] == 0)
{
atm[qu[i]] = -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?
Reply With Quote
  #28 (permalink)  
Old 05-18-2012, 01:02 AM
Jorgen Grahn
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On Tue, 2012-05-15, James Kuyper wrote:
> On 05/15/2012 03:27 PM, pembed2012 wrote:
> ...
>> The code was by a "genius programmer" who has gone away, his code was
>> superefficient but maybe the variable names were not helpful and the
>> documentation was minimal :-)

>
> 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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Reply With Quote
  #29 (permalink)  
Old 05-18-2012, 07:22 AM
Ike Naar
Guest
 
Posts: n/a
Default Re: Segmentation Fault

On 2012-05-17, pembed2012 <once@was.enough.invalid> wrote:
> 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 ?
Reply With Quote
  #30 (permalink)  
Old 05-19-2012, 07:37 AM
Gordon Burditt
Guest
 
Posts: n/a
Default Re: Segmentation Fault

> If the code crashes, how do you conclude that it is superefficient?

If the code does not have to work correctly, it can be done in 0 machine
cycles with 0 bytes.

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:14 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.