473,882 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seriously struggling with C

RG
Greetings friends,

This semester I have started a course in C programming. I was moving
along fine until I reached to the topic of loops (feeling embarrassed
among you elite programmers). My prof. would post program questions
and the solutions online. For practice I would try to do the problems.
I would reach to a certain point in the code, for example as far as
error trapping, but when the loop arrives, like knowing whether to use
for, while do, how to properly use the increment and decrements, and
counters,I am just not proficient in it and the class is moving ahead.
Eventually i would have to look at the solution and wondering to
myself, the reason i could not think of it. What ticks me off is that
other kids are getting this stuff easily, while I am having a hard
time.Kindly advise me on what actions I shoul take. I would
particularly like to have an idea of the thought process to engage in
when given the programme to write.
Thanks for your time and consideration.

RG

Feb 20 '06
160 4806
In article <dt**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Vladimir
S. Oka <no****@btopenw orld.com> writes
Chris Hills wrote:
In article <dt**********@n wrdmz03.dmz.ncs .ea.ibs-infra.bt.com>,
Vladimir S. Oka <no****@btopenw orld.com> writes
Herbert Rosenau wrote:

On Thu, 23 Feb 2006 11:07:29 UTC, "Dik T. Winter"
<Di********@cwi .nl> wrote:

> In article <46************ @individual.net > "Richard G. Riley"
> <rg***********@ gmail.com> writes:
> > On 2006-02-23, Dik T. Winter <Di********@cwi .nl> wrote:
> ...
> > > machine it did not work. It appeared that on the umpteenth
> > > occurrence
> > > of some call to some routine something was wrong. It is
> > > impossible
> > > to detect such using breakpoints or watchpoints. Using proper
> > > printf's
> >
> > This is simply not true. Since you must have some idea where the
> > problem is to insert the "printf" then you have some idea where
> > to set your breakpoint to detect "naughty data" : then you can
> > do a stack trace to see where this data originated.
>
> Also when the problem occurs on something like the millionth call
> to some routine?

Yes. A conditional breakpoint does the trick. Let the call pass
undebugged 999.999 times and trace the 1,000.000th run through.

Not if you're running a system with (hard) real time requirements.
Conditiona l breakpoints slow things down horribly, a
only if you are using a cheap and nasty ICE. A decent ICE has
(virtually) no effect on the circuit.


Yes, if the condition is simple "Nth pass" type, or of similar
complexity. I doubt that anything more complex than that is so light,
and I really had that in mind.


No, even filtered trace with multiple (nested) conditions and watch
points make no difference on a decent ICE.
It's much better to add a condition
to the code itself, and when it hits N-th execution stop and dump out
any system state you're interested in.


What crap! you are changing the system in order to look at it. So the
system you are looking at is NOT the same as the original system you
wanted to test.


If you're so strict in this, then even the (virtually) no effect of the
ICE is no good, as the system won't be the same either.


The effect a good ICE has will be less than the normal manufacturing
tolerances on a circuit. I have had this confirmed by more than one ICE
user who looked into this.
If you /really/
don't want to change system timing, then maybe adding debug code that
stays in even in production is the way to ensure timing is always the
same? (In what I do it's quite feasible, as the debug output is simply
not wired out for the end user.)
This is the case with some systems. However systems at this level
usually demand that an ICE is used.


(I'll have it known that I'd rather not mess with either conditional
breakpoints or debug output, in the first place.)
I have used ICE where the system you test IS the one you ship with no
test code permitted in the released system. This is for high integrity
systems with 20 years MTBF where no bug fixing is possible.


I admit I haven't been involved in anything even close to this level
(it's still hard real time, but consumer electronics, and with 9-18
months before thrown put for the latest and greatest)...


try telecoms systems and not just the deep or sub-marine cables. then
there are satellites, smart cards not to mention cars (some 100 MCU in
each these days)
Your methods would have you removed from the project very quickly.


...but you'd be surprised how quickly I can get into line once I'm told
the specs. ;-)


Fair enough.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Feb 26 '06 #151
In article <44************ ***@yahoo.com>, CBFalconer
<cb********@yah oo.com> writes
"Vladimir S. Oka" wrote:
Chris Hills wrote:
Vladimir S. Oka <no****@btopenw orld.com> writes

... snip ...

It's much better to add a condition
to the code itself, and when it hits N-th execution stop and
dump out any system state you're interested in.

What crap! you are changing the system in order to look at it.
So the system you are looking at is NOT the same as the original
system you wanted to test.


If you're so strict in this, then even the (virtually) no effect
of the ICE is no good, as the system won't be the same either. If
you /really/ don't want to change system timing, then maybe adding
debug code that stays in even in production is the way to ensure
timing is always the same? (In what I do it's quite feasible, as
the debug output is simply not wired out for the end user.)


All this foofaraw assumes the system has hardware debugging
assistance in the first place. This is not guaranteed by the C
standard.


The C standard is irrelevant to this discussion. The Sw could be C. C++,
Assembler PLm, pascal etc an ICE is a hardware debugger. s simulator
is a software debugger.
In fact, even the ability to set and use breakpoints is
not guaranteed (which will generally foul up the timing).
Breakpoints will change the timing because the stop the flow but watch
points do not neither do conditional breakpoints, trace etc
What is
guaranteed is the ability to execute printf and similar statements.
but these change the timing and memory map. They do not give any certain
indication of the state of the program under test.
Even systems with hardware debug assistance usually have sharp
limits, such as in the count of breakpoints settable.
an ICE is a hardware system. Al the ICE I have used do have a limit on
break points. you can only set one per address in memory. on an 8 bit
system this is in execcs of 64K breakpoints.

For JTAG systems it is only 2 HW breakpoints but unlimited Sw
breakpoints. However the number of breakpoints actually needed is
usually quite small
Even their
use can alter timing, since enabling them almost certainly alters a
microcode path during instruction fetch.


As the breakpoints are done in the ICE not on the target this is not
correct. The effect a good ice has on the target HW is less than the
fluctuations in production tolerances. In any event it is MANY orders
of magnitude less than the disruption caused by using printf etc
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Feb 26 '06 #152
Chris Hills wrote:
<cb********@yah oo.com> writes
"Vladimir S. Oka" wrote:
Chris Hills wrote:
Vladimir S. Oka <no****@btopenw orld.com> writes
... snip ...

> It's much better to add a condition
> to the code itself, and when it hits N-th execution stop and
> dump out any system state you're interested in.

What crap! you are changing the system in order to look at it.
So the system you are looking at is NOT the same as the original
system you wanted to test.

If you're so strict in this, then even the (virtually) no effect
of the ICE is no good, as the system won't be the same either. If
you /really/ don't want to change system timing, then maybe adding
debug code that stays in even in production is the way to ensure
timing is always the same? (In what I do it's quite feasible, as
the debug output is simply not wired out for the end user.)


All this foofaraw assumes the system has hardware debugging
assistance in the first place. This is not guaranteed by the C
standard.


The C standard is irrelevant to this discussion. The Sw could be C.
C++, Assembler PLm, pascal etc an ICE is a hardware debugger. s
simulator is a software debugger.


In case you failed to notice, this newsgroup is c.l.c, on which the
C language, as described by the various standards, is discussed.
BTW Pascal is always capitalized.
In fact, even the ability to set and use breakpoints is
not guaranteed (which will generally foul up the timing).
Breakpoints will change the timing because the stop the flow but
watch points do not neither do conditional breakpoints, trace etc


You are extremely naive. Without hardware support watchpoints also
alter the timing. Probably much more so than conditional
breakpoints, since they require intercepting every instruction.
What is
guaranteed is the ability to execute printf and similar statements.


but these change the timing and memory map. They do not give any
certain indication of the state of the program under test.


Not the memory map. You seem determined to find a free lunch.
TANSTAAFL.

--
Some similarities between GWB and Mussolini:
a) The strut; b) Making war until brought up short:
Mussolini: Ethiopia, France, Greece.
GWB: Afghanistan, Iraq.
Feb 26 '06 #153
CBFalconer wrote:
Flash Gordon wrote:
... snip ...
Yes, that is my point. When writing test for your SW, whether
system level, function level, or somewhere in between, do
everything in your power to break it.


When I had something ready to test, I used to look for the least
computer ready personnel, usually a sweet young thing, or a
near-retirement secretary, and get them to try it out. I would
tell them not to worry about breaking anything, just do whatever
comes into your mind. This served both to reduce their fear of the
evil machines, and to uncover my goofs.


I agree that is a good thing.

Something else I like to do when a bug is discovered is to make sure the
rest of the code handles the problems caused by the bug as well as
possible and sort that our before fixing the bug. E.g. making sure that
the SW correctly reports to the user that the SW is bust (with a message
that will give me some clue) and then aborts without corrupting the
database.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Feb 26 '06 #154
Ian Collins wrote:
Flash Gordon wrote:

Although you and, I'm sure, most people here do try to break SW when
testing, I've come across far to many people in my career who when
writing internal tests at whatever level write test to prove the kit
works instead and thus fail to find the problems. Once to the extent
that they failed to find a problem I had reported to the designer on
reviewing the design & code as I found out a lot later when another
project tried to reuse the code and hit one of the problems I had raised.
That's one of the reasons test first is a good thing, the tests are the
design and the code is written to pass the tests, thus implementing the
design.


I'm not, and never have, argued that writing the tests first is wrong.
In fact, I agree with it.

You still have to design your tests to try and make the code fail rather
than assuming that the code will be written sensibly.
I agree wholeheartedly that system level tests must be written with the
objective of breaking the code. This is hard for the original
developers to do and in my opinion, best left to dedicated testers. I'm
not saying it can't be done by the developers, but it takes a lot of
discipline.


Agreed. Some of us have had the required level of discipline, and also
the required time, a lot don't.

BTW, I've also been one of an independent team of testers in the past.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Feb 26 '06 #155
In article <44************ ***@yahoo.com>, CBFalconer
<cb********@yah oo.com> writes
Chris Hills wrote:
<cb********@yah oo.com> writes
"Vladimir S. Oka" wrote:
Chris Hills wrote:
> Vladimir S. Oka <no****@btopenw orld.com> writes

... snip ...
>
>> It's much better to add a condition
>> to the code itself, and when it hits N-th execution stop and
>> dump out any system state you're interested in.
>
> What crap! you are changing the system in order to look at it.
> So the system you are looking at is NOT the same as the original
> system you wanted to test.

If you're so strict in this, then even the (virtually) no effect
of the ICE is no good, as the system won't be the same either. If
you /really/ don't want to change system timing, then maybe adding
debug code that stays in even in production is the way to ensure
timing is always the same? (In what I do it's quite feasible, as
the debug output is simply not wired out for the end user.)

All this foofaraw assumes the system has hardware debugging
assistance in the first place. This is not guaranteed by the C
standard.
The C standard is irrelevant to this discussion. The Sw could be C.
C++, Assembler PLm, pascal etc an ICE is a hardware debugger. s
simulator is a software debugger.


In case you failed to notice, this newsgroup is c.l.c, on which the
C language, as described by the various standards, is discussed.
BTW Pascal is always capitalized.


However the C standard has no relevance to the debugging in question.
In fact, even the ability to set and use breakpoints is
not guaranteed (which will generally foul up the timing).
Breakpoints will change the timing because the stop the flow but
watch points do not neither do conditional breakpoints, trace etc


You are extremely naive. Without hardware support watchpoints also
alter the timing.


All the way though this thread I have been referring to ICE and
Emulators which are hardware.
Probably much more so than conditional
breakpoints, since they require intercepting every instruction.
What is
guaranteed is the ability to execute printf and similar statements.


but these change the timing and memory map. They do not give any
certain indication of the state of the program under test.


Not the memory map. You seem determined to find a free lunch.
TANSTAAFL.


Using printf to debug will change the memory map. You have to include it
and therefore it will not be the same as when you don't include it/

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Feb 26 '06 #156
Chris Hills wrote:
<cb********@yah oo.com> writes

.... snip ...

You are extremely naive. Without hardware support watchpoints also
alter the timing.


All the way though this thread I have been referring to ICE and
Emulators which are hardware.


No you haven't. Firstly, such things are OT for c.l.c. Secondly,
this disagreement began with your objection to one line conditional
statements, as being hard to set breakpoints on, to which I
responded that printfs were a more useful debug mechanism to me.
ICE and emulators have nothing to do with that. In fact an ICE is
almost impossible to implement for modern systems where one inch is
a long transmission line. I have yet to see an emulator that
preserves the timing of the hardware.

Hint: The name of a newsgroup is a clue to the matters discussed.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

Feb 26 '06 #157
CBFalconer <cb********@yah oo.com> writes:
Chris Hills wrote:
<cb********@yah oo.com> writes

... snip ...

You are extremely naive. Without hardware support watchpoints also
alter the timing.


All the way though this thread I have been referring to ICE and
Emulators which are hardware.


No you haven't. Firstly, such things are OT for c.l.c. Secondly,
this disagreement began with your objection to one line conditional
statements, as being hard to set breakpoints on, to which I
responded that printfs were a more useful debug mechanism to me.

[snip]

I don't think it was Chris who objected to the one-line conditional
statement. I *think* I remember who it was, but I'm too lazy to track
it down.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 26 '06 #158
On 2006-02-26, Keith Thompson <ks***@mib.or g> wrote:
CBFalconer <cb********@yah oo.com> writes:
Chris Hills wrote:
<cb********@yah oo.com> writes

... snip ...

You are extremely naive. Without hardware support watchpoints also
alter the timing.

All the way though this thread I have been referring to ICE and
Emulators which are hardware.


No you haven't. Firstly, such things are OT for c.l.c. Secondly,
this disagreement began with your objection to one line conditional
statements, as being hard to set breakpoints on, to which I
responded that printfs were a more useful debug mechanism to me.

[snip]

I don't think it was Chris who objected to the one-line conditional
statement. I *think* I remember who it was, but I'm too lazy to track
it down.


It was me : for the simple reason it makes it nigh on impossible to
set break points on condition branching.

printfs only work in the most trivial environment and certainly are
useless on anything running in a multiprocess server like environment.

But I think thats all been covered.

--
Remove evomer to reply
Feb 26 '06 #159
Keith Thompson wrote:
CBFalconer <cb********@yah oo.com> writes:
Chris Hills wrote:
<cb********@yah oo.com> writes

... snip ...

You are extremely naive. Without hardware support watchpoints also
alter the timing.

All the way though this thread I have been referring to ICE and
Emulators which are hardware.


No you haven't. Firstly, such things are OT for c.l.c. Secondly,
this disagreement began with your objection to one line conditional
statements, as being hard to set breakpoints on, to which I
responded that printfs were a more useful debug mechanism to me.

[snip]

I don't think it was Chris who objected to the one-line conditional
statement. I *think* I remember who it was, but I'm too lazy to track
it down.


Oh, maybe it was that objectionable joker who refused to stay on
topic, and got plonked by many (including me). Riley or
something. It still doesn't really matter, ICEs are hardly on
topic here.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Feb 27 '06 #160

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
2102
by: Stan | last post by:
Hey everyone, I've got a computer science class and we're working on C++. I am struggling with nested loops and have a really simple assignment, but I can't get it to run the loop. I need to run a loop that has someone guess at a number 5 times and if they get 45, it tells them how many guesses they needed. It also has to tell them if they leave the range of guesses from 0 to 100. I need help. Can somebody help me please!!!
4
2010
by: Rowan | last post by:
Hi there, it's me again. I am having trouble with a view again. I am trying to do a calculation, but there are some checks that need to be taken into consideration. Maybe a view is not the right way to deal with this. I don't know. This is the beginning of my query. SELECT coalesce(f.filenumber, i.filenumber) as filenumber, i.InvoiceNumber, i.InvoiceValue, il.lineid, MPF = .21 * (il.UnitCost * il.UnitQty + il.AddMMV - il.MinusMMV -...
26
6772
by: dagger | last post by:
Hi there. I'm using C under FreeBSD with the gcc compiler and am having a bit of trouble using the calloc and realloc calls. As an example the code snippet: #include <stdio.h> int main() { char *ptr;
4
5625
by: Angus Comber | last post by:
Hello I have received a lot of help on my little project here. Many thanks. I have a struct with a string and a long member. I have worked out how to qsort the struct on both members. I can do a bsearch on the long member (nKey) but I am struggling to do a search using the string member. The code I am running appears below. It doesn't crash or anything. It is just that when I do the last bsearch using "192.168.1.3" I SHOULD find...
5
4067
by: | last post by:
I am really struggling to conceptually understand classes in C# especially the use of the strange keywords 'static' 'void' and 'override'.... Is there a 'idiots' way of understanding these concepts broadly before even touching a line of code.... Thanks Jason
2
1281
by: mjeaves | last post by:
Hello there, Hope someone can help. I have data arriving in a table, a Cron job is triggered when the data arrives. ---- table_1 id (unique)
97
5588
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in the first place. Anyone else heard about this development? The Master
0
1050
by: Steve | last post by:
I'm struggling to get proper runtime and designtime dpi values. In the forms .designer.vb I've added the following code after InitializeComponent() Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0F, 96.0F) Me.AutoScaleMode = Windows.Forms.AutoScaleMode.Dpi And in my code behind the form, I've added,
11
22896
by: briankind | last post by:
Hello i have these radio buttons and i wish to have the corresponding textboxes to be visible when the radiobutton is selected. any Help? snippets. thanks thanks in adv Bry
0
9931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10725
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10830
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9557
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7956
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.