Lab 3 Discussion, ECE637, Spring 2008

Hi this is about another really powerful tool. As Professor Bouman has been talking a lot about debugging I suggest (if you are not using one already !) that one can make use of GDB (GNU debugger). It is a really powerful tool to debug codes. We can track status of all variables and see them change as the program execcutes. It is really easy to use especialy with the Emacs editor.

A link for GDB is :

http://www.yolinux.com/TUTORIALS/GDB-Commands.html

I found the debugging tool really cool and useful esp for lab 3 where we have to code from scratch.

Singanallur V Venkatakrishnan

A simple stack implementation --nicholas.klosterman.1, Wed, 06 Feb 2008 15:04:39 -0500 reply

Since this class is about DIP and not data structures I feel help in implementing a stack is worthwhile.

  1. define SIZE 250 //choose a size you feel is appropriate

void push(struct pixel i); struct pixel pop(void);

struct *topofstack, *stackptr, stack[SIZE]?;

initialize these variables in main()

   topofstack= stack; /* tos points to the top of stack / stackptr= stack; / initialize p1 */

void push(struct pixel i) {

   stackptr++; if(stackptr== (stackptr+SIZE)) {
       printf("Stack Overflow.n"); exit(1);
   } *stackptr= i;

}

struct pixel pop(void) {

   if(stackptr== stackptr) {
       printf("Stack Underflow.n"); exit(1);
   } stackptr--; return *(stackptr+1);

}

This is only a way to implement a stack in C. I'm sure that there are more elegant ways. To declare stackptr and topofstack in main as globals and use them in other files you'll need to declare them as extern in the subsequent files. This lets the linker know that the variables it is using are declared in another file.

A simple stack implementation --nicholas.klosterman.1, Wed, 06 Feb 2008 15:08:09 -0500 reply

Although the wiki gave me some unexpected formatting, I believe that the code is still all there. There is one correction. The line under "initialize these variables in main" should have stackptr=stack; on it's own line and not commented out.

... --mehmet.gunal.1, Mon, 11 Feb 2008 10:50:16 -0500 reply

I haven't used any additional functions for stacking purposes. I kept track of the stack pointer at an integer "i", and incremented "i" as I add in to my stack "B" and decremented "i" as I take out from my stack "B". I hope this helps.

gcc version issues --joshua.s.hayden.1, Thu, 14 Feb 2008 14:20:20 -0500 reply

I was having very strange memory issues compiling this program in Linux.

I don't know why yet, but if I switch back from gcc version 4.1.2 to gcc version 3.4.6, everything works fine. The VISE lab uses gcc version 3.4.6, so you'll be fine if you're running your program there.

If anyone has an idea as to why gcc version 4 breaks my program, please let me know.

Alumni Liaison

EISL lab graduate

Mu Qiao