473,883 Members | 2,607 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 4808
In article <46************ @individual.net > "Richard G. Riley" <rg****@gmail.c om> writes:
On 2006-02-23, Dik T. Winter <Di********@cwi .nl> wrote:

....
It can and it cant. It can show you where resulting cast/assign
mismatches go wrong as you examine the data. In this case though,
assuming you hadnt cast everythign to death, the compiler should
have been a help.


No cast in sight. gcc does nog give warnings in this case.


The debugger would format the data as it was declared : it would be
fairly obvious to anyone stepping the code that a DOUBLE was being
forced into an INT for example.


Yes, once you suspect that was happening in the code, it would be obvious
through a debugger. But it would be just as obvious looking at the
source (as I did).

The only problem was that the program did not give results close to what
was (mathematically ) expected, so where to start? Something is wrong,
but you have really no idea what. (And indeed, mathematics proved to
be right and the program was wrong.)
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 24 '06 #131
In article <tf************ **@phaedsys.dem on.co.uk> Chris Hills <ch***@phaedsys .demon.co.uk> writes:
In article <Iv********@cwi .nl>, Dik T. Winter <Di********@cwi .nl> writes

....
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?


This is where and ICE is essential.


What *is* ICE? I never heard about it. And I am doing programming for
over 30 years.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 24 '06 #132
In article <pv************ **@phaedsys.dem on.co.uk> Chris Hills <ch***@phaedsys .demon.co.uk> writes:
In article <Iv********@cwi .nl>, Dik T. Winter <Di********@cwi .nl> writes ....
I would find a debugger useful here.


You think so? Even when the problem shows up only after many many
minutes of running?


That is why I use an ICE.


What *is* an ICE? In my 30+ years of programming experience I never
have seen the acronym.
Especially where it is something like a
certain combination of interrupts causing a problem in timing every now
and again.
The program I write have nothing to do with interrupts and timing at all,
so what are you talking about?
The ICE should be part of the unit and system test system. When things
go wrong then it becomes the debugger.


What system are you talking about? I am doing a simple combinatorial
problem. A simple back-tracking problem, it goes wrong when your
back-tracking goes wrong.

BTW, changing memory lay-out can be beneficial when finding bugs. This
was one of the ways I detected an off-by-one error in the garbage
collector of the Algol 68 system we used quite a long time ago.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 24 '06 #133
Dik T. Winter wrote:
In article <tf************ **@phaedsys.dem on.co.uk> Chris Hills <ch***@phaedsys .demon.co.uk> writes:
> In article <Iv********@cwi .nl>, Dik T. Winter <Di********@cwi .nl> writes

....
> > > 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?

>
> This is where and ICE is essential.


What *is* ICE? I never heard about it. And I am doing programming for
over 30 years.


Obviously not on embedded systems. In Circuit Emulator.

--
Ian Collins.
Feb 24 '06 #134
[re tracing and debugging]
In article <Iv********@cwi .nl>, Dik T. Winter <Di********@cwi .nl> writes
Also when the problem occurs on something like the millionth call to some
routine?
In article <tf************ **@phaedsys.dem on.co.uk> Chris Hills
<ch***@phaedsy s.demon.co.uk> writes:
This is where and ICE is essential.

In article <Iv********@cwi .nl> Dik T. Winter <Di********@cwi .nl> wrote:What *is* ICE? I never heard about it. And I am doing programming for
over 30 years.


"In-Circuit Emulator", typically a special piece of hardware you
put around a CPU (or entire card, or whatever) that captures the
signals at each pin (or card edge or whatever -- but note that
most card- or bus-level devices are not called ICEs but rather
called "logic analyzers", despite doing much the same thing).
Additional software interprets those and tells you what the CPU
(or other hardware) was doing at each clock cycle.

ICEs can be very useful in tracking down Heisenbugs. However, they
are not the be-all and end-all even at the hardware level. The
Heisenburg effect applies even there: sometimes adding wires adds
enough parasitic capacitance to change the behavior of a
supposedly-digital circuit.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Feb 24 '06 #135
In article <rg************ @news.flash-gordon.me.uk>
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
I also spent time as I say working in the Test Engineering Department,
and since we were building test equipment (which also had to test
itself) we developed the attitude of assuming that the SW has to survive
and continue working properly as much as possible even if fundamental
parts of the system are failing in ways you can't conceive of, a
philosophy that I find very useful.


Of course, this all has to be judged on a cost/benefit basis. It
is difficult to use the software to test itself if the CPU is not
even executing the boot instructions stored in the boot ROM, for
instance. :-)

I often find it useful to check for "impossible " conditions in
low-level code, but I have to trade that against the lack (at that
point) of a strategy for dealing with such conditions, and the
slowdown effect of performing an "unnecessar y" test.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Feb 24 '06 #136
Dik T. Winter wrote:
In article <pv************ **@phaedsys.dem on.co.uk> Chris Hills
<ch***@phaedsys .demon.co.uk> writes:
> In article <Iv********@cwi .nl>, Dik T. Winter <Di********@cwi .nl>
> writes

...
> > > I would find a debugger useful here.
> >
> >You think so? Even when the problem shows up only after many many
> >minutes of running?

>
> That is why I use an ICE.


What *is* an ICE? In my 30+ years of programming experience I never
have seen the acronym.


ICE stands for In Circuit Emulator. It's often heavily used in
development and debugging of embedded systems. These, being non-hosted
environments, rarely, if ever, have an OS you can use to run
development applications.

Modern CPU manufacturers provide (a standardised) hardware interface
(e.g. JTAG) which exposes the CPU internals and allows you to poke into
it using a hardware plug-on connected to your PC which runs the
debugger. This then enables you to place breakpoints, read and write to
memory, stop and start execution, all from the comfort of your hosted
environment, and essentially without disturbing the system being
tested. The software tools provided usually (at least the good ones)
combine a debugger with at least an execution profiler, but may also
include other useful tools for analysing and debugging the system.

This is not a very exhaustive, and probably not pedantically correct
explanation, but I didn't want to be too lengthy (or my English fails
me this early morning).
> Especially where it is something like a
> certain combination of interrupts causing a problem in timing every
> now and again.


The program I write have nothing to do with interrupts and timing at
all, so what are you talking about?


The problems with interrupts is that you generally have no idea when (or
even if) they'll happen. If you allow for more than one type (e.g.
keyboard, mouse) they can have different priorities and be allowed to
interrupt each other, i.e. one interrupt service routine (ISR, here's
one more acronym) can easily be interrupted itself for another to run.

Even in a single threaded execution model getting the priorities and
various dependencies wrong can wreak havoc, and be hard to debug. If
you have a multitasking environment, especially with hard real time
requirements, and multiple asynchronous interrupts, it gets even worse
(e.g. a mobile phone will typically run at least half a dozen tasks,
and can be interrupted from at least as much sources, at least one of
the tasks will have hard real time requirements, and will be severely
short of time anyway).
> The ICE should be part of the unit and system test system. When
> things go wrong then it becomes the debugger.


What system are you talking about? I am doing a simple combinatorial
problem. A simple back-tracking problem, it goes wrong when your
back-tracking goes wrong.


Probably the ones like a mobile phone. It's rarely possible to backtrack
your problem, especially with difficult bugs).

However, having been involved in just such development, and on the hard
real time part as well, I can attest that I had to resort to an ICE or
a debugger maybe three times in the past 5 years. Judicious debug
logging and analysing code at hand (third party legacy, no less) proved
to be very successful.

I found that the ICEs and the such are of most use for the developers of
hardware drivers for the embedded (and other) devices.

--
BR, Vladimir

It is wise to keep in mind that neither success nor failure is ever
final.
-- Roger Babson

Feb 24 '06 #137
Flash Gordon wrote:
Ian Collins wrote:
Flash Gordon wrote:
>
The sense isn't false if the tests are good and written first. In
my opinion, test added after the code is written are second rate.
On one of the projects I worked on early in my career (written in
Pascal) I don't think any of us ever used the debugger and we did
not write the tests until after we wrote the code, and even then the
tests were system level. However, when we did write the tests we
went a long way out of our way to try to think of every single way
we could break the system. Running out software with some of the kit
switched off, unplugging cables whilst it was running, swapping 525
line cards in to what was meant to be a 625 line system (we had a
525 line variant with the same code base) etc. During that testing
we found a significant number of bugs. During the remaining 10 years
of my time in the company, through many versions of the SW,
including getting fresh graduates to no experience or domain
knowledge to do changes, the customers found very few bugs. However,
rerunning these manual system level tests after changes *did* find
problems, and each time the customer found a bug we extended our
tests to catch the bug.

What you are describing are what I'd call acceptance tests, working
on the code form the outside confirming that the system behaves as
expected by the customer.


No, we were not trying to confirm it behaved as expected. Quite the
reverse, we were being as devious as possible in trying to prove it
did *not* work. We succeeded in that. Our customer acceptance tests,
on the other hand, where designed to demonstrate it worked as expected
and took far less time.


I think there's a misunderstandin g on which side of the table you and
Ian are assuming you're sitting at. I believe Ian meant /he/ was a
customer running acceptance tests on, say, a piece of 3rd party
software. You seem to be looking at it from the 3rd party POV.

IMHO, both of you are correct. When we sell a device we run it through a
battery of standardised tests to prove to the customer it works. When
we buy in a piece of software to use in our device, we test it in all
sorts of nasty ways looking to break it.

Obviously, internally, we also have tests for /our/ code that try to
break it before it gets to the customer.

--
BR, Vladimir

The opposite of a correct statement is a false statement. But the
opposite
of a profound truth may well be another profound truth.
-- Niels Bohr

Feb 24 '06 #138
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.
Conditional breakpoints slow things down horribly, and almost
invariably give you a system that just simply does not work, as it
breaks all the timing constraints. 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.

--
BR, Vladimir

Ducharme's Precept:
Opportunity always knocks at the least opportune moment.

Feb 24 '06 #139
On Fri, 24 Feb 2006 00:29:09 UTC, Flash Gordon
<sp**@flash-gordon.me.uk> wrote:
Herbert Rosenau wrote: <snip>
Oh look, my debugger broke on the file open failing. <fx: looks at file
system> Odd, the file is there and with correct permissions. <fx: Looks
at nicely timestamped logs from system here and system 200 miles away>
Ah, I see, that server 200 miles away is taking longer than the
specified time to put the file on my server.

There are times when debug logs can be *far* easier to use than a
debugger. Not always in my opinion, but they do exist.
I've found never such a situation. It was always at lest
- knowing how to use the debug
- exact knowledge of how the system works
(what does an API do excactly on which condition and what side
effects
are prior, during and after the system api gets called are active
Or another situation that really has happened to me. Two different
programs one in Java the other in C are interacting in an incorrect
manner. However, the system only fails more than once every few weeks
when under heavy load at customer sites in the week before month end
when they are running hundreds of invoices through the system hourly. Do
I ask my customer if they will let me know each time they start a new
session so I can attach a debugger to it (I can't wait the minimum
likely time of weeks minimum it would take for me to replicate the
problem once and don't know *exactly* what the customers 50 users in
that department are doing to cause it) or do I spend an hour putting in
some debug logging and ask them to run with that build for a bit?
Oh, for such remote environment we had setup our CORBA applications
running on the same mashine as CORBA is designed to work local or
remote even under another OS. Setting up an test environment had not
even a single change of the code needed - but a bit defferent
environment. So debugging server and client in parallel was more nice
as to fiund some technices to setup debug logfiles.
I chose putting in some debug logging. I had a significant piece of the
puzzle a couple of days later (they could not install the debug build
immediately) and the next day I had the solution. Far less work than
using a debugger would have been.

It is quite common for those reporting bugs to miss out some critical
piece of information in what they are doing. The addition of easily
enabled logging is gradually making it far easier for us to see exactly
what the customer is doing to cause the failure, something a debugger
can never do.


I had an similar situation. One of our customers reported constantly
an abnormal end of one application - but nobody and nothing was able
to reproduce that until we crippled a mashine to exact the same
hardware environment the user had. So it was easy in 9 from 10 runs to
produce the abort - but it was impossible to find the cause for even
then. Using a debugger to catch it was resulting in unable to get the
abort reproduced! Using the same debugger then more advanced and it
was absolutely clear what the cause was and using the brain it was
easy to fix by manually syncronise the threads at that critical point
against the stand rules. The next version of the OS brought a new
system API to make that syncronising inside the kernel to make that
problem going away.

But anyway once found the cause me and all collegauges of my company
had learned how to avoud that problem by design. The cause was: when
the main thread was dying before any other thread was alredy die
(means loosed any occurence of the thread in the thread table of the
kernel) the whole process crashed.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
Feb 24 '06 #140

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
5589
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
9933
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
9786
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
11125
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10734
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
10836
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
10407
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
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5794
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
5982
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.