473,836 Members | 1,292 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 4751
On 2006-02-22, Michael Mair <Mi**********@i nvalid.invalid> wrote:
Richard G. Riley schrieb:
On 2006-02-22, Chris Dollin <ke**@hpl.hp.co m> wrote:
Richard G. Riley wrote:

>I think this may be the "something different". When I say "use the
>debugger " I mean a human working interactively with a tool to locate
>a point of failure in a system, by placing break/watch-points on
>location s/triggers and looking with the eyes at the machine state.

You are discussing rationally so lets stick with this. Everything you
have just said is exactly what I mean by using a debugger. A debugger
isnt only there to locate a point of failure although clearly that is
a major use. It can also be used, as I have repeatedly stated, to test
the system at run time. You can even connect to running processes in
most systems.

I'm sure you can. You don't make it clear in "It can also be used, as I
have repeatedly stated, to test the system at run time" whether you mean
manual or automated testing. Dinking around by hand at run-time with a
debugger would strike me as an approach of last resort. Doing so
Connecting to external processes is more rare, I grant you.
/routinely/ strikes me as an act of madness - I mean, I'm fallible
enough already.


lets not get stuck on connecting to remote processes : lets keep it to
using the debugger to test and check new code.


This is very nice for limited amounts of possible input.
But in this case, even simple unit test schemes in combination
with logging suffice.


Possibly. my own perference and that of the teams I have worked with
is to give the code a run through with the debugger befoe submitting
to unit tests. If you can get away without that then great.

[This is different, as far as I can tell, from Chris Hill's description
of automated testing using ICEs etc.]

I *always* use a debugger to run through any meaningful critical
code. It enables me to cast an eye over memory, stacks, locals etc. It
is an added safety barrier beyond my own smug ability to write error
free code :)

Well, I don't know what you're doing; I've just never been in a situation
where this would be helpful. I'm under no illusions about my ability to
write error-free code, it's just that using a debugger doesn't give me
value for money.
We must come from different schools of thought. I and every programmer
I have ever worked with routinely step through code alone or with a
colleague to check boundary conditions, memory initialisations etc. It
is a bedrock of any development I have done. Using break expressions
means I can put in wierd and wonderful parameters and have the
debugger break when a function is suddenly passed something it doesnt
know how to deal with. We are, after all, fallible.


Every serious project with >= 0.5 MLoC I was ever involved in
had its own resource management to track down certain kinds of
errors.


I dont doubt this and have used automated systems too where appropriate.
In addition, every single complex feature can be switched off
and internal states and debug indices can be made visible in
the output. Without, debugging would be sheer madness.
A good logging system guarded by switches is always invaluable. Again,
no disagreement here.
Only exception: Paranoia checks with debug mode "asserts".
Unit tests should suffice to feed all kind of "weird and
wonderful" parameters to a module. Regression tests make the
whole thing "round" -- customers and other colleagues tend to
find things one could not imagine when stepping through in the
debugger.
Again fine : but using a debugger to examine while developing
module(s) can do no harm and, for me, frequently raises issues with
regard to sensible program flow and frequently hilights unnecessary
loop depths and other such quirks which can be optimised out.

The trace and logging outputs are just builtin "printf()
debugging". When working with huge amounts of data, this may
be the only way to get a first idea what is happening. Without
this idea, you typically don't know what is going wrong, let
alone where.
I would never personally use printfs but a system specific log
function which may, or may not, end up using printf or some other form
of information provision.

>What you describe sounds perfectly sensible - but I wouldn't describe
>it as "using a debugger"; I think this is the disconnect.
>
>[I don't know if I'd call the tools you mention "debuggers" , either, but
> it's too late to know for sure whether I wouldn't have /before/ this
> discussion.]

Debugger. Eclipse "debugger". gdb. All debuggers.

debuggers (and why is the Eclipse debugger awarded scare-quotes?) ...

All code development tools.

... not (necessaily) debuggers: there's a difference here.
Debugging is part of development in my world. maybe we are talking
nomenclature differences here?


Mmmh. I don't know:

- Feature Specification and System Design
<-> Product Test based on the Spec, developed at the same time
by someone who is not the author of the Spec.
- One to several levels of component specifications and design
documents
<-> Automated Developer Tests, external and internal.
- Regular Automated Regression Tests incorporating Product and
Developer Tests as well as a large base of simple and complex
input
- Tracking system to track all requirements and limitations
through the different levels.
- Source control and configuration management.
During Specification and Design Phases: Several reviewers.
Occasional Code Reviews.

Sources of Bugs:
1) "Holes" in the design or specification documents. Most of
the time caught by the test specification process.
2) Implementation errors. Usually caught by the developer
tests.


2) Is my "debugging" phase. generally.
Debugging: Mostly necessary in legacy code written under time
pressure or circumventing such a process.
All code has bugs :-;

For smaller projects: An adapted version of the above.

All very much used in any real SW development cycle.

There are other approaches than routine manual use of debuggers.
Such as? An initial use of a debugger to monitor a programs progress
can show up lots of issues as well as facilitating routines boundary
tests. It just makes plain sense.


Design better test drivers and frameworks. It pays.


If everything were so perfect it would. Even with designs, code reads,
automated testing I just find it better and more profitable to step
through my code at the earliest stage to be sure things are going the
rigth way and that nothing silly is going to waste time & money by
forcing the code to be thrown back at me or someone else at a later stage.

Cheers
Michael


thanks.

--
Remove evomer to reply
Feb 22 '06 #81
Richard G. Riley wrote:

Yes, I can vaguely remember doing such things about 25 or 30 years
ago. I outgrew it. I find a sound design and functional breakdown
works much better.

Do you write standalone SW that only you maintain?

I find it incredulous that as a programmer, a debugger isnt a very
important tool on your list.

Noone is suggesting that good design and functionaly breakdown are not
important. What is indisputable though is that a debugger provides a
programmer with an easy, flexible way to perform run time checks and
manipulation of his code. ESPECIALLY when adding or modifying a legacy
system. Frequently you may need to call a poorly document external
function and need to bounds check it to be sure you can handle the
data and that it doesnt fall over with your "perfectly sound" input
data.


Adopt Test Drive Development and you will find yourself using the
debugger less and less. I hardly ever use mine these days, if a test
breaks, I just back out my last change and redo it.
--
Ian Collins.
Feb 22 '06 #82
On Wed, 22 Feb 2006 16:04:57 +0000, in comp.lang.c , Chris Dollin
<ke**@hpl.hp.co m> wrote:
Richard G. Riley wrote:
I *always* use a debugger to run through any meaningful critical
code. It enables me to cast an eye over memory, stacks, locals etc. It
is an added safety barrier beyond my own smug ability to write error
free code :)


Well, I don't know what you're doing; I've just never been in a situation
where this would be helpful.


Whoa there boys.
It sounds to me like Richard isn't talking about a debugger at all,
but about automated tools like purify, quantify, lint etc. These
remove bugs, but theyre not debuggers as I (and everyone I have ever
worked with) thinks of them. A debugger is an IDE you fire up to step
through the code so you can examine variables manually. The former I
would always advocate using on any production code. The latter is a
development tool, not a testing tool.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 23 '06 #83

"Richard G. Riley" <rg***********@ gmail.com> wrote in message
news:46******** ****@individual .net...
On 2006-02-22, August Karlstrom <fu********@com hem.se> wrote:
Richard G. Riley wrote:
There is another one from Bertrand Russell:

"The trouble with the world is that the stupid are cocksure and the
intelligent full of doubt."


That's a really good one.
August


Heh, and ties in nicely with your .sig :-;


One of my favorites:

"...there are three classes of intellects: one which comprehends by itself;
another which appreciates what others comprehend; and a third which neither
comprehends by itself nor by the showing of others; the first is the most
excellent, the second is good, the third is useless."

Machiavelli, The Prince, Chapter 22
Rod Pemberton
Feb 23 '06 #84

"Richard G. Riley" <rg***********@ gmail.com> wrote in message
news:46******** ****@individual .net...
On 2006-02-22, CBFalconer <cb********@yah oo.com> wrote:
"Richard G. Riley" wrote:

... snip ...

It must be a personal thing. For me the debugger is as crucual a
part as the editor : I would normally always step through the
debugger just to sniff out any issues with uninitialised stuff,
pointer run throughs etc. Its why IDEs put so much effort into the
debugger part these days.


Yes, I can vaguely remember doing such things about 25 or 30 years
ago. I outgrew it. I find a sound design and functional breakdown
works much better.


Do you write standalone SW that only you maintain?

I find it incredulous that as a programmer, a debugger isnt a very
important tool on your list.


I wrote my first program in 1981 (or was it '79?). Anyway, in all that time
through maybe fourteen languages, I've only had to use a debugger twice.
Once for a compiler issue and the other to track data between multiple
processes. Printf's or it's equivalent is sufficient. Since I've
essentially never needed it, I have no choice but to consider the use of a
debugger to be a serious indicator that you're doing something wrong.
Perhaps, you need to develop a set of coding rules or a style guide to help
correct the errors your encountering?
Rod Pemberton
Feb 23 '06 #85
Rod Pemberton wrote:
One of my favorites:

"...there are three classes of intellects: one which comprehends by itself;
another which appreciates what others comprehend; and a third which neither
comprehends by itself nor by the showing of others; the first is the most
excellent, the second is good, the third is useless."

Machiavelli, The Prince, Chapter 22


I think the first is excellent only if it incorporates the second. No
one wants to hang out with a besserwisser. ;-)
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Feb 23 '06 #86
In article <11************ **********@g47g 2000cwa.googleg roups.com> "Vladimir S. Oka" <no****@btopenw orld.com> writes:
Richard G. Riley wrote:

....
Its why debuggers exist. Only the most trivial
or tiny code can be maintained or properly examined with messy and
time consuimg printfs. printfs only show what you *think* you need to
know : not the true state of memory, locals, stacks, memory blocks.


You seem to completely ignore the world of deeply embedded devices.


I did not see the original, but there is more to it. Recently I have
written quite a few C programs that either gave incorrect output (blatantly
incorrect) or crashed with a "segmentati on fault". Debuggers are in these
cases generally useless (I found). In both cases the problem was with the
logic of the program, not with errors with respect to C. In the second
cases the debugger proved to be of no use at all, the only thing the
debugger (gdb) said when the error occurred was that almost none of the
variables could be accessed (the problem proved to be overly deep
recursion due to a problem with the logic). And the first was almost
always due to a problem with the logic. That is the kind of thing a
debugger will not help. (The programs all were about combinatorial
problems.)

For instance, in one case I declared an array of int's rather than
double's. How is a debugger going to help me to find the problem?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 23 '06 #87
Again not received the original, that is why I respond to this.

In article <dt**********@m alatesta.hpl.hp .com> Chris Dollin <ke**@hpl.hp.co m> writes:
Richard G. Riley wrote:
In addition printfs dont give you watchpoints, breakpoints etc. I cant
even believe we are having this discussion to be honest, although I
suppose you're not necessarily defending it : just that it can be done
- on that we are agreed.


Oh, I /am/ defending it. In my (limited) C experience, I have not
needed to resort frequently to a C debugger. I would expect to need
one less nowadays than I used to, as well.


What I am missing here is that using breakpoints debugging code can be
*more* time consuming than using printf's to give the state. I once
had to debug a program I had written (80k+ lines of code). On some
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
and scrutinising the output will get you much faster the answer to why
it did not work.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 23 '06 #88
In article <pa************ *************** *@bsb.me.uk> Ben Bacarisse <be********@bsb .me.uk> writes:
I'd write

for (i = 0; check(i, i + 2); i++);

There are cases (though I can't think of any right now!) where the
relationship between control variables is too complex (or expensive) to
capture, but when you can, I think having one is clearer.


for(i = 0, j = 1; check(i, j); i++, j = (j * 2) % n)?

And, yes, I do use such loops on occasion.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 23 '06 #89
Richard G. Riley wrote:

Littering code with printfs or the quivalent plain sucks unless its
for logging purposes and is well DEFd out : even then it can
unecessrily break p the flow and readability of the code.
I agree.
Its why debuggers exist. Only the most trivial
or tiny code can be maintained or properly examined with messy and
time consuimg printfs. printfs only show what you *think* you need to
know : not the true state of memory, locals, stacks, memory blocks.
Even the most complex code can be maintained with the aid of
comprehensive unit tests, no need for printfs. If these are done well,
you will seldom, if ever, have to use your debugger.
The last C project I did - a compiler/shortcode interpreter for
a scripting language - I hardly used a debugger at all, and when I
did, it was to get a stack-trace and line-number because that
doesn't happen for free when the code went whoopsie.

If you can get away with it fine. Its certainly not something that
would generally be encouraged in any programing environment I have
been involved in.

What is 'it' in this context?
It must be a personal thing. For me the debugger is as crucual a part
as the editor : I would normally always step through the
debugger just to sniff out any issues with uninitialised stuff,
pointer run throughs etc. Its why IDEs put so much effort into the
debugger part these days.

That just shows you don't have tests.....

--
Ian Collins.
Feb 23 '06 #90

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

Similar topics

22
2090
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
2006
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
6769
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
5621
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
4061
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
1277
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
5567
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
1047
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
22886
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
9814
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
9666
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
10249
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
9368
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
7786
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
6976
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
5645
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...
1
4447
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.