Hello! I am taking a scientific computing class, where we are doing some programming in C, and right now our assignment is to add commentary to an existing program explaining what every line does (starting at the line that says Start here!). As you can see in the code below, I have done some of the commentary. However, I am confused about what some of the lines and their various symbols mean. For instance, what does the arrow (->) do? How do I describe its function in the lines below? Also, besides the obvious of setting the left side equal to the right side, what do these two lines:

norm_solution = fabs(u0) + fabs(v0);
r = LTE/(EPSILON_REL*norm_solution + EPSILON_ABS);

do in the code? Do you think I'm just supposed to put the obvious as my answer? Or is there something else major I am missing? And last, can someone tell me if the commentary I have made is correct? I want to make sure I'm getting what this code means.

Thank you in advance for any help you can provide!!

void compute_dt(TIMESTEP *timestep, double u0, double v0, double u1, 
	double v1, double u2, double v2) // based on LTE
{
    double dt = timestep->dt, dt_new;
    double r, LTE, norm_solution;
    double EPSILON_REL = 1.e-6, EPSILON_ABS = 2.2e-16;

    // COMMENT: Start here!
    LTE = (16./15.)*(fabs(u2-u1) + fabs(v2-v1));
    // Sets the norm of the LTE to the norm of (u2,v2)-(u1,v1)
    norm_solution = fabs(u0) + fabs(v0);
    // 
    r = LTE/(EPSILON_REL*norm_solution + EPSILON_ABS);
    // 

    if (r <= 2.) {
    // Tells the loop to run for values of r less than or equal to 2 
        timestep->REDO_STEP = NO;
        // 
        dt_new = dt/pow(r, 1./5.); /* since LTE ~ dt^5 */
        // Sets the new dt equal to the normal dt divided by r to the 1/5 power
        dt = min(dt_new, 2.*dt);
        // Sets the normal dt equal to the minimum of the new dt and two times
        // the normal dt. 
    }
    else {
    // else if r > 2 the code will do the following threee statements
        timestep->REDO_STEP = YES;
        // 
        timestep->LAST_STEP = NO;
        // 
        dt /= 2.;
        // Sets dt equal to itself divided by 2. 
    }
    timestep->dt = dt;
    // 
}

Any good c book will help will you lot than others.

This would have to be close to one of the most stupid assignments I've ever heard of. It just supports my claims on the quality of CS education these days.

I have looked in my very bare-bones C book (its not even for this class, its for another one, so it is also about Scheme, Prolog, and others, so the section about C is relativelty small) and know that the arrow operator has something to do with pointers, but I really don't understand what it does. I have read that it is the same as saying (*pointervariable).foo, but I don't know how to describe what it does. Can anyone help me?

lol srsly thats soo stupid thats y most professional programmers arent from college there self taught lol
and btw arrow operator is ptr to structure -> they should tell you basics before you should even tell you to translate program to english

Look guys, I know this may seem stupid to you, and I agree. I'm not even a CS major, I'm a math major, but they are making me take this scientific computing class and an intro to programming languages class. So I agree totally that this is not really that major or important or anything, but I still need to pass the class. I'm not a programmer, and I don't want to be one, because I'm not very good at it, but I do want to get this assignment right.

Okay, so it is a pointer to a structure...how is that different from a pointer? When the line of code says:
timestep->REDO_STEP = YES;
does that mean that timestep is a pointer to REDO_STEP? What does the YES part of the line mean? Can someone just deconstruct this for me and tell me how to describe its function?

Thanks for trying to help, everyone. I do appreciate the efforts. :-)

#define YES 1

struct time{
int REDO_STEP;
char xyz;
/* other variables may be declared here*/
};

struct time *timestep;  /*timestep is pointer to struct time */
/* to access the member of structure we use arrow(->) or dot(.) operator. arrow is used with pointers */ 
/*so here to access REDO_STEP, we use timestep->REDO_STEP.
Now if we write*/
timestep->REDO_STEP = YES;
/* this means timestep->REDO_STEP now contains value equal to YES.
Had we declared struct time timestep(not a pointer), then to access the member we 
will use timestep.REDO_STEP = YES. (notice dot operator between timestep and REDO_STEP).
In similar way other members of structure will accessed. */

Hope you would have got enough idea to proceed further.

Thank you so much, codeguru. I was just not understanding this operator at all, but this makes sense to me! Thank you. I think I can get the rest of it, because its all pretty much the same.

Again, I so appreciate your help, codeguru. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.