Re: Answer needed

From: Tom (tvaus_at_sympatico.ca)
Date: 02/16/05


Date: Wed, 16 Feb 2005 00:39:45 -0500

Thank you for your reply.
I tend to agree with you that if you write a piece of code
that works as you expected it to just means that you are
just exercising what you already know. Trying something
new and different can be fun, especially if you get errors or
unexpected results. Finding out what went wrong and where
helps you learn from your mistakes. What I find fun is determining
where things went wrong and correcting the problem. What can I
say, I like puzzles.

I write code for embedded systems for my employer. Products and
in-house 'custom hand crafted testsets'. I also design the hardware.
Fixing coding problems for old products also falls in my domain.

I remember having to fix a problem on an old product and the original
programmer had left long before. It was one of those "it happens every
now and then with no specific pattern of operations" to reproduce the
fault with any consistency. It took about two months of playing around
with the code and re-mapping variables from internal RAM to external
RAM (80C31 microcontroller specific) before I tracked down the
offending function call. It was a function to store data in an array of
message
arrays. It used to be implemented using pointers and pointer manipulation
without any bounds checking. Only if a certain message type was saved
as the last element of the array the data was written outside the allotted
buffer
space and would overwrite other needed variables and cause problems.
I re-wrote the offending function with proper checks of the pointer value.

I guess I could summarize that when using pointers, be careful what the
pointer points to.

Thanks for you input,
Tom.

"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:QsobVxAfQaECFwzN@robinton.demon.co.uk...
> In article <g6fQd.7104$4I5.395943@news20.bellglobal.com>, Tom
> <tvaus@sympatico.ca> writes
> >If you would please be so kind as to elaborate upon your reply.
> >Specifically, how does writing a small independent app result
> >in 'broken code'? Can one not test an idea (algorithm) in a small
> >and easily managed app before adding the code to a larger program
> >with the appropriate modifications made to work in the larger project?
> >You now have my full attention, not only to benefit me but others in the
> >group.
>
> This wasn't testing an algorithm but dealing with what should be
> produced by a statement that contained two instances of undefined
> behaviour. As the result of undefined behaviour can be anything
> including what you expect writing code to see what the result will be
> is, at best, a complete waste of time and at worst will teach you
> something that is not true.
>
> Once a programmer can write code that is free of UB, understands the
> implications of unspecified behaviour (such as the order of evaluation
> of sub-expressions) and implementation defined behaviour (and has check
> the implementation) writing test code to ensure that an algorithm does
> indeed do what s/he expects is fine. Indeed I encourage students and
> readers of my book to experiment. But I also warn them about the evils
> of attempting to learn C++ (or any programming language) as if it were
> an experimental science.
>
> If things work as you expect you have actually learnt nothing (except
> possibly confirming an erroneous understanding), you only learn when
> things do not work or not as expected. But even then you must be careful
> to find out why and not just speculate as to possible reasons.
>
> >
> >Tom.
> >
> >"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
> >news:HQZeKFIGK0DCFwra@robinton.demon.co.uk...
> >> In article <YKGPd.11$cp2.2344@news20.bellglobal.com>, Tom
> >> <tvaus@sympatico.ca> writes
> >> >I assume that you have access to a PC with a C compiler.
> >> >(relatives, friends, school, etc.)
> >> >Why don't you just code a small program for your question
> >> >and see what happens.
>
> --
> Francis Glassborow ACCU
> Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
> For project ideas and contributions:
http://www.spellen.org/youcandoit/projects



Relevant Pages

  • Re: gdb not catching out-of-bounds pointer
    ... is also not defined by the C-standard, IOW: writing code in anything ... provided the library writer knows what the compiler writer guarantees ... etc.) that don't point into the same array than I would about the sort ... of pointer aliasing issue that started this sub-thread. ...
    (comp.unix.programmer)
  • Re: Get/Put read/write efficiency
    ... Yes, you can do that, as has been mentioned in a couple of responses, by setting up a temporary Byte array the same size as the data block you wish to load and then loading the file data into it and then using CopyMemory to copy the loaded block of data data into the main large array which contains the entire file. ... You can do exactly what you have asked (tell it to start writing from array(x) and specify how many bytes you want) by setting up a SafeASrray structure and pointing it at the desired data position in the large array. ... This involves swapping only a four byte pointer no matter how many data bytes you wish to read or write. ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem with pointer to array of structures
    ... I have been writing with C ... but usually I try to avoid complicated pointer stuff such as ... not an array of pointers to structs? ...
    (comp.lang.c)
  • Re: fast array copy
    ... > I'm writing a function that updates an array. ... a pointer NOT an array and an array is NOT a pointer. ... There are some types of lists you can use depending on the type of ...
    (comp.lang.c)
  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)