Re: Answer needed
From: Tom (tvaus_at_sympatico.ca)
Date: 02/16/05
- Next message: David White: "Re: [C] error C2065: 'i' : undeclared identifier??(the whole program)"
- Previous message: nick: "Re: [C] error C2065: 'i' : undeclared identifier??(the whole program)"
- In reply to: Francis Glassborow: "Re: Answer needed"
- Next in thread: Chris \( Val \): "Re: Answer needed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: David White: "Re: [C] error C2065: 'i' : undeclared identifier??(the whole program)"
- Previous message: nick: "Re: [C] error C2065: 'i' : undeclared identifier??(the whole program)"
- In reply to: Francis Glassborow: "Re: Answer needed"
- Next in thread: Chris \( Val \): "Re: Answer needed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|