Andrew Que Sites list Photos
Projects Contact
Main
   I was pleased at an implementation I did today.  It was an other RAM test on system start, and this time I was able to use pure assembly.  What was neat about this was testing it out.  The test had to be able to run without access to the system RAM (ROM only) and send out a message should the test fail.  The RAM test is small, and I wrote it the assembly fairly quick.  What supprised me was that it worked almost in it's entirity from the begining, and for assembly code it was pretty clean.  For the test, our techs modified a board so there was a jumper on the RAM's clock, which was the easiest line to get at.  Thus, pull the jumper, the RAM never gets a clock, and thus never does anything.  Without the jumper, the system does do anything--but it does fail a RAM test and the failure is reported.  I thought it was a cool project.
   Pictured are Dave, Jenna and Melissa from when we met up Saturday night.

August 25, 2009

An other C gotcha

Spent most of the day hunting down a bad "*". It was a simple mistake, and one easy to overlook. It goes something like this.

static int *location = (int*)SOME_STATIC_LOCATION;

The above had been moved so it was initialized inside of an init function, rather then the declaration. The code changed to this:

static int *location;

// ...

void SomeFunction()
{
   // ...

   *location = (int*)SOME_STATIC_LOCATION;

   // ...

}

Buried in hundreds of other lines, this mistake is easy to overlook. What happened is simple: a copy and paste copied too much. Instead of setting the location of the pointer, the uninitialized pointer was dereferenced and whatever it pointed to was set to some constant. This is not what was intended.

Now here is something to think about. Some people do like to add the asterisk directly in front of the declaration. Maybe do it because of this situation:

int some_int, *some_int_pointer;

This is legit. However, I've always been of the school "one statement per line". In this case, I would break the declaration into two lines. And, I always place a space between the asterisk and the variable name.

int some_int;
int * some_int_pointer;

I still use no space when dereferencing with an asterisk.

   *some_int_pointer = 0x1234;

There are a few other operations I do this for as well:

   &some_address
   (int)some_cast
   some_array[ INDEX ]

The mistake in the above scenario is a little harder to make when declaring variables like this. The asterisk in the decoration (meaning pointer) has a different meaning then the asterisk in variable usage (meaning dereference). It is unlikely someone would have copied too much if there was a space after the asterisk in the declaration.

Now some crazy stuff and why I use the spacing and naming methods I do:

int * const * volatile pointer_A;
int const * const * volatile pointer_B;
int const * * pointer_C;

Read it from right to left and it makes sence:

    "pointer_A is a volatile pointer to a constant pointer to an integer."

    "pointer_B is a volatile pointer to a constant pointer to a constant integer"

    "pointer_C is a pointer to a pointer to a constant integer".

Now this:

   int * value;
   int result;

   result = 1000 * *value * result;

See how the spacing helps to distinguish the multiplication from the dereferencing?

To finish up, let's look at some more C code examples of what can be done, but probably shouldn't be used.

   int value = 100;
   int * value_pointer = &value;
   int * * value_pointer_pointer = &value_pointer;
   int result;

   // This will not compile
   result = 1000 * value;

   // This is ligitimate
   result = 100 ** value_pointer;
 
   // This will compile with a warning, it is ligitimate
   result = *value_pointer + value_pointer;

   // This compiles with a warning and I have no idea why anyone
   // would want to do this, but it can be done.
   result = value_pointer +* value_pointer;

   // This yeilds 510 but is discuraged because "**" is used in some
   // documentation to mean "to the power of"
   result = 5**value_pointer+10;

   // Will not compile
   result = 5**value_pointer_pointer+10;

   // This will compile
   result = 5***value_pointer_pointer+10;

2 comments have been made.

From ERica

August 29, 2009 at 10:55 PM

I read through this like three times. I don\'t understand it, but I want to. What is a value pointer and where are all these equations coming from?

From Andrew Que (http://www.DrQue.net/)

Wisconsin, USA

September 01, 2009 at 3:47 AM

I will post an article and see if I can explain more about pointers. The equations in this article are completely arbitrary--they are given to show issues with the language syntax, not to do something useful. But now that you mention it, the equations are mostly line equations: m x b or just m x and x b.
   Went out to the garden today and was supprised to see that pumpkin had invaded.  I didn't plant pumpkin this year, so it must be the stuff we planted last year that didn't come up.  Not only has it taken over most of the length of the garden, it has started to invade the lawn.  I happen to be a big fan of pumpkin, so I'm pretty happy about this.

2 comments have been made.

From Simeon

August 24, 2009 at 4:02 AM

This is at The Garage? I\'ve never seen anything growing there but...nice try, hacker narcs.

From Talon the magnificent

here

August 27, 2009 at 12:50 PM

you where are you living now a days? i have got a long ass road trip coming up and am looking for pit stops
   On the drive to Wisconsin, my truck started doing something that had me quite alarmed.  When we stopped for a bathroom and food break, I noticed that the idle was really high--like I was constantly reving the engine.  In fact, it was harder to stop because the engine was runing hard.  Why this had me alarmed was a road trip back in 1999 where I was driving a van that did the same thing.   I noticed the problem in Chicago, and just north of Dayton Ohio, the engine threw a rod.  So when I noticed my truck doing the same thing.... yeah.
   Anyway, we made it to the Garage, but I was concerned about the return trip.  While I know all the theory about how engines work (I use write software for fuel injection), I know nothing about trouble shooting them.  Nonetheless, I poped the hood and stuck my head in.  I noticed a sound I had not ever herd before, like that of escaping air.  It was a steady sound--not pulsed--and didn't seem to change with engine speed.  When I turned off the engine, I could hear air leaking our of something for several seconds after shut-down.  So, I decided to look for places where air could leak out.
   I found a little tube with a big hole in the side.  Whenever I need to cover a hole, I get ducktape.  So here it is in the picture, the fix.  I closed up the hole and cranked up the truck.  And... it worked.  The engine was idling like normal.  While it is still possible my truck wants to explode, at least this symptom is fixed.  So, for better or worse, I'm going stop worrying.
   There are a lot of problems with my truck.  It started burning oil--not enough to need to fill the oil regularly--but enough so you can smell it.  The radiator has a leak at the top, so you can't keep the reservoir full.  And the thermostat doesn't make it to the dash--I have no indication of water temperature.  One of the biggest problems, which will kill the truck, is the frame is rusting out.  One can find chunks of my chasy in the drive way, and every now and then a fairly large piece.  I will not be able to continue to drive this vehicle for ever, and it's becoming clear that I won't be able to put off a replacement for too much longer.

2 comments have been made.

From Simeon

Your face

August 24, 2009 at 4:01 AM

Bravo, Dr. Mechanic.

From Steve

JaneHell, WI

August 24, 2009 at 8:10 PM

Yeah, I can\'t say I\'m too mechanically inclined either. Hell, I was proud of myself just figuring out when my clutch wire got snapped (which I fixed with some electrical tape). My truck had a shit-ton of problems too, but with little money all I could do was just make do with what I had until it finally died. I was damn lucky things came together at the right time so that I was able to get my VW, otherwise that wouldn\'t have been happening. Hell, I\'d probably still be without a vehicle. Seriously though, I know your truck\'s on its last legs. Not sure how long Rockwell will keep you on board, but either way, I seriously recommend investing at least some of the money you\'re earning from this contract towards a different ride. I know it\'s inconvenient and may set you back some, but you\'re not gonna get much accomplished without reliable transportation.
Horsepower Fallacy

Horsepower Fallacy

   I've been using VirtualBox at home now for several months, but today I tried it on a work project.  I was working after hours on an experiment I wanted to try.  We use a Linux box setup to do our cross-compile  Building the tool chain isn't trivial and would create a lot of paper work to in order to verify it was generating identical code (aerospace--verification is very important).  So when ever we do a build, we log into the Linux machine and run the compile.  Turns out that not everyone is able to log into that machine (network policies and such), so they can't compile binaries.  So I had an idea: VirtualBox.
   My plan was pretty simple.  Setup a Linux system on a virtual machine, copy over the tool chain and attempt to compile.  Since the tool chain is identical there should be no issues with the created result.
   I started with a Debian base.  Our Linux box doesn't have a GUI and we don't need one, and Debian is small.  At the company, we are behind a proxy.  However, Debian asked for the auto-proxy configure URL and the network connection seemed to work fine.  This was one of my points of worry, since the network is controlled fairly tightly.  The install was rather uneventful except when I tried to install the VirtualBox add-ons.  I was using the mirror at Argonne National Laboratory figuring the download would happen a little faster then from the main site.  But when I went to try and install the GNU C compile, it couldn't find it.  I thought I had changed my mirror site in the Debian config, but I really had not.  After a lot of messing around, I found and corrected my mistake and GCC on installed.
   Our build system has a strange directory tree for the tool chain, but I reproduced it all and before long could get most of the compile to happen.  It took a few small changes to the make file in order to compile completely, but I think I can work around them.  After getting a binary, I put it in some hardware and like I had expected, it worked fine.  Looks like this VirtualBox setup is going to work.
    Pictured is Noah inspecting his go-car... his car.

1 comment has been made.

From Steve

JanesHell, WI

August 21, 2009 at 4:38 PM

I definately plan to put VirtualBox on my new system whenever I get it up and running. Debian is one of the Linux distributions I want to get and try out, among others. Have you tried using other distributions to see how well they work with the setup you described?