Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > give me some tips

Reply
Thread Tools

give me some tips

 
 
Rod Pemberton
Guest
Posts: n/a
 
      03-12-2006

"Michael Mair" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rod Pemberton schrieb:
> > "Yuri CHUANG" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> >
> > I'd start by learning how to solve some problems and write some programs
> > well. After solving and implementing
> > a few problems, you'll know whether you are better at "top-down" or
> > "bottoms-up" design. Each person has a
> > biological preference for each one (FYI, those who prefer "top-down" are

N,
> > and "bottoms-up" are S, in Myers-Briggs personality Type Indicator).

>
> Hmmm, and what am I if I prefer one approach for some kinds of problems
> and the other for other kinds of problems and the
> midlevel-to-up-and-down and the come-from-top-and-bottom for yet
> other classes of problems?


For the MBTI, X is used when an individual is balanced between the two
categories. Most people show a dominance for one category or the other.

But, you bring up a very good point: people's preference or natural
abilities can interfere with solving specific problems since certain
problems can only be solved when started from a certain point. Frequently,
both "top-down" and "bottoms up" programmers start having problems
"in-the-middle". The "top-down" programmer didn't allow for any special
cases (too generic) and has problems implementing the details, and the
"bottoms up" programmer has too much unnecessary detail and can't grasp the
"big-picture."


RP


 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      03-12-2006
"Rod Pemberton" <(E-Mail Removed)> writes:
[...]
> The following are my opinions for the C language are really are _specific_
> to _my_ programming style. Others may not
> have problems with the same areas of C that I do, so they probably have
> their own list of issues. You'll need to develop
> your own list of "problem areas" over time:
>

[...]
> 7) avoid the use of type qualifiers (const, volatile, restrict), except
> where necessary, because they can hide programming errors


I don't see how "const" in particular can hide programming errors.

Use type qualifiers whenever they're appropriate. (restrict is
complex and seldom necessary; don't worry about it until you know what
you're doing. restrict is also new in C99, so many compilers don't
support it.)

> avoid the use malloc(), except for dynamic data, because it leads to
> memory allocation errors


What else would you use malloc() for?

Corollary: avoid the use of any feature X, because it leads to X
errors.

Better advice: use malloc() carefully.

> 9) typedef structs and give them file scope (i.e., "global"), it can simply
> certain problems


Typedefs for structs are usually unnecessary. You can just declare

struct foo {
...
};

and refer to the type as "struct foo"; there's no real need to use a
typedef to create a second name for the type. (This is a somewhat
controversial point; many programmers prefer to be able to refer to
the type using a single identifier.)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
 
 
 
Richard G. Riley
Guest
Posts: n/a
 
      03-12-2006
On 2006-03-12, Keith Thompson <(E-Mail Removed)> wrote:
>> 9) typedef structs and give them file scope (i.e., "global"), it can simply
>> certain problems

>
> Typedefs for structs are usually unnecessary. You can just declare
>
> struct foo {
> ...
> };
>
> and refer to the type as "struct foo"; there's no real need to use a
> typedef to create a second name for the type. (This is a somewhat
> controversial point; many programmers prefer to be able to refer to
> the type using a single identifier.)
>


I'm glad this came up : personally I like the more "in your face"
robustness of this as opposed to using the typedef. There seems to be
just something "wrong" about the whole struct definition in
conjunction with typedef : I cant quite place what it is, although if
you look at the two examples below I think this is what has sometimes
led me astray in an "at a glance" read of strange code:

typedef struct point {
int x;
int y;
} Dot;

struct point {
int x;
int y;
} upperLeft;


Could only be me, but I like to see (in C) the struct keyword at the
point of instantiation.
 
Reply With Quote
 
Richard G. Riley
Guest
Posts: n/a
 
      03-12-2006
On 2006-03-12, Yuri CHUANG <(E-Mail Removed)> wrote:
> "No newline at the end of your output" is really a problem? I've never
> learned that before.
> So I desire to know some tips about writting a program perfectly.Can
> anyone give me some tips which are hardly learned from textbook or
> easily ignored?
> Thank you very much.
>


Just reading some of the replies which may or may not have got tied ip
on "\n" at the end of each output:

Take a look at the exit(EXIT_SUCCESS) function. Its a start to
understanding some issues/considerations when leaving a program.
 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-12-2006

"Richard G. Riley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 2006-03-12, Keith Thompson <(E-Mail Removed)> wrote:
> >> 9) typedef structs and give them file scope (i.e., "global"), it can

simply
> >> certain problems

> >
> > Typedefs for structs are usually unnecessary. You can just declare
> >
> > struct foo {
> > ...
> > };
> >
> > and refer to the type as "struct foo"; there's no real need to use a
> > typedef to create a second name for the type. (This is a somewhat
> > controversial point; many programmers prefer to be able to refer to
> > the type using a single identifier.)
> >

>
> I'm glad this came up : personally I like the more "in your face"
> robustness of this as opposed to using the typedef. There seems to be
> just something "wrong" about the whole struct definition in
> conjunction with typedef : I cant quite place what it is, although if
> you look at the two examples below I think this is what has sometimes
> led me astray in an "at a glance" read of strange code:
>
> typedef struct point {
> int x;
> int y;
> } Dot;
>
> struct point {
> int x;
> int y;
> } upperLeft;
>
>
> Could only be me, but I like to see (in C) the struct keyword at the
> point of instantiation.


Usually, there is no need for tye type-definition, i.e., 'point', in the
structure declaration when using a typedef:

typedef struct {
int x;
int y;
} Dot;

/*...*/

/*...some function...*/
{
Dot dot_x1y1,dot_x2y2;
}

This has been beaten to death on other threads which was why I posted
"The following are my opinions for the C language ... are _specific_
to _my_ programming style," but Keith ignored...

RP





 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-12-2006

"Michael Mair" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rod Pemberton schrieb:
> > "Yuri CHUANG" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...


> Michael
> --
> E-Mail: Mine is an /at/ gmx /dot/ de address.


Although there are a number of "Michael Mair" 's, that leads me to:

Professor (FH) Magister Michael Mair of FH-Modul, University of Innsbruck,
and MCI Innsbruck, Wien(Vienna), Austria.

Is that you? I'll assume that it is for the rest of this post.

Which translates roughly as having a PHD and/or Masters with a university of
applied sciences. I'm sure I botched that. But, since your English is very
good for an Austrian, I'll let you correct that. All of which led to two
pictures: one on FH-Modul and one on FH-Wien. Nice ties. FH-Modul appears
to be a tourism and hospitality university (Fachhochschulstudiengänge für
tourismus-management).

You've mentioned teaching in your other posts. Assuming I've got the
correct person: "Doc", what exactly are you degreed in? Tourism management?


Rod Pemberton


 
Reply With Quote
 
Michael Mair
Guest
Posts: n/a
 
      03-12-2006
Rod Pemberton schrieb:
> "Michael Mair" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>Rod Pemberton schrieb:
>>>"Yuri CHUANG" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed) egroups.com...

>
>> Michael
>>--
>>E-Mail: Mine is an /at/ gmx /dot/ de address.

>
>
> Although there are a number of "Michael Mair" 's, that leads me to:
>
> Professor (FH) Magister Michael Mair of FH-Modul, University of Innsbruck,
> and MCI Innsbruck, Wien(Vienna), Austria.
>
> Is that you? I'll assume that it is for the rest of this post.


No, that is not me.
I have a University Diploma in "Technomathematik" which essentially is
maths sprinkled with computer science and one engineering discipline.
In my case that is engineering mechanics but I also had a look into
electrical engineering. This course appealed to me because you get
to understand the respective "languages" and are open to specialize
as you feel like.
I did some research in numerical mathematics (simulation and
optimization of dynamic mechanical systems) afterwards, in the course
of which I also gave a C course to relieve other people at our chair
and in order to have students who actually learnt the basics of C so
that we could hire them. In addition, I like teaching as it helps me
learn the stuff I thought I knew that much better.

Right now, I am working in an area where I need knowledge about
compiler construction and discrete mathematics -- an area I am more
enamoured with than numerical mathematics.


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-12-2006

"Michael Mair" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rod Pemberton schrieb:
> > "Michael Mair" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >>Rod Pemberton schrieb:
> >>>"Yuri CHUANG" <(E-Mail Removed)> wrote in message
> >>>news:(E-Mail Removed) egroups.com...

> >
> >> Michael
> >>--
> >>E-Mail: Mine is an /at/ gmx /dot/ de address.

> >
> >
> > Although there are a number of "Michael Mair" 's, that leads me to:
> >
> > Professor (FH) Magister Michael Mair of FH-Modul, University of

Innsbruck,
> > and MCI Innsbruck, Wien(Vienna), Austria.
> >
> > Is that you? I'll assume that it is for the rest of this post.

>
> No, that is not me.


Darn, and thanks for not taking any offense. Hopefully, it was a cheap
thrill. I found at least five "Rod Pemberton" 's in the US. I could
understand that one was black (must have been a Pemberton slave owner).
But, it was interesting to find a Vietnamese individual with that name! Go
figure...

> I have a University Diploma in "Technomathematik" which essentially is
> maths sprinkled with computer science and one engineering discipline.
> In my case that is engineering mechanics but I also had a look into
> electrical engineering. This course appealed to me because you get
> to understand the respective "languages" and are open to specialize
> as you feel like.


Ah, okay, I thought you seemed a bit more like an EE than a CS.

> I did some research in numerical mathematics (simulation and
> optimization of dynamic mechanical systems) afterwards, in the course
> of which I also gave a C course to relieve other people at our chair
> and in order to have students who actually learnt the basics of C so
> that we could hire them.


"who actually learnt the basics of C"

I find that comment humorous. I knew quite a few degreed CS majors who
couldn't program. Of course, I knew a few EE who didn't know what an
electron was either...

> In addition, I like teaching as it helps me
> learn the stuff I thought I knew that much better.
>
> Right now, I am working in an area where I need knowledge about
> compiler construction and discrete mathematics -- an area I am more
> enamoured with than numerical mathematics.


"compiler construction"

Yes, not coming from a CS background. I could _really_ use a huge amount of
good public information in this area. I've found stuff at a PHD level and
or ideas which perhaps are patented. I can't use information like that. I
need things like: whether it's easier to use stacks or binary trees. How to
identify when to use an optimization in the compiler backend. Is it better
to use tokens (abstract syntax tree) or string processing of text (concrete
syntax tree)? I could really use Necula's et. al. CIL (C Intermediate
Language) if it only had a flex and bison grammar...


Rod Pemberton



 
Reply With Quote
 
Michael Mair
Guest
Posts: n/a
 
      03-12-2006
Rod Pemberton schrieb:
> "Michael Mair" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> in the course
>>of which I also gave a C course to relieve other people at our chair
>>and in order to have students who actually learnt the basics of C so
>>that we could hire them.

>
> "who actually learnt the basics of C"
>
> I find that comment humorous. I knew quite a few degreed CS majors who
> couldn't program. Of course, I knew a few EE who didn't know what an
> electron was either...


There was nothing humorous at the time. We even considered
banning applicants from a certain information technology
course for our job offers as they made up ninety percent of
the applications (with the shiniest certificates) and about
three percent of the knowledge.


>>Right now, I am working in an area where I need knowledge about
>>compiler construction and discrete mathematics -- an area I am more
>>enamoured with than numerical mathematics.

>
> "compiler construction"


I am not sure whether this is the correct translation.
Essentially, whatever you can learn from the Dragon Book or
Muchnick's book.

> Yes, not coming from a CS background. I could _really_ use a huge amount of
> good public information in this area. I've found stuff at a PHD level and
> or ideas which perhaps are patented. I can't use information like that. I
> need things like: whether it's easier to use stacks or binary trees. How to
> identify when to use an optimization in the compiler backend. Is it better
> to use tokens (abstract syntax tree) or string processing of text (concrete
> syntax tree)? I could really use Necula's et. al. CIL (C Intermediate
> Language) if it only had a flex and bison grammar...


Some of the en.wikipedia.org pages are a decent starting point
if it comes to basic concepts.

Apart from that: Have a look at graph theory; there is much nice
stuff on the web and, as discrete maths goes, it is a fun subject
as you can state really deep problems on a sheet of paper within
five minutes so that everyone understands the problem but the
proof took a hundred years to be found and conversely can prove
things in an easily understandable way. If you understand graph
theory and get an intermediate representation of some code, you
are ready to do general (not target specific) optimisations.

I am not actually writing a traditional compiler but am involved
in the optimisation of an intermediate representation of code;
the output of the product is C.
More about that only via PM and only as far as I am allowed to
tell about it.


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      03-12-2006

"Michael Mair" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rod Pemberton schrieb:
> > "Michael Mair" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >

> There was nothing humorous at the time. We even considered
> banning applicants from a certain information technology
> course for our job offers as they made up ninety percent of
> the applications (with the shiniest certificates) and about
> three percent of the knowledge.
>
> >>Right now, I am working in an area where I need knowledge about
> >>compiler construction and discrete mathematics -- an area I am more
> >>enamoured with than numerical mathematics.

> >
> > "compiler construction"

>
> I am not sure whether this is the correct translation.
> Essentially, whatever you can learn from the Dragon Book or
> Muchnick's book.


I've not heard of these, but will look.

> > Yes, not coming from a CS background. I could _really_ use a huge

amount of
> > good public information in this area. I've found stuff at a PHD level

and
> > or ideas which perhaps are patented. I can't use information like that.

I
> > need things like: whether it's easier to use stacks or binary trees.

How to
> > identify when to use an optimization in the compiler backend. Is it

better
> > to use tokens (abstract syntax tree) or string processing of text

(concrete
> > syntax tree)? I could really use Necula's et. al. CIL (C Intermediate
> > Language) if it only had a flex and bison grammar...

>
> Apart from that: Have a look at graph theory; there is much nice
> stuff on the web and, as discrete maths goes, it is a fun subject
> as you can state really deep problems on a sheet of paper within
> five minutes so that everyone understands the problem but the
> proof took a hundred years to be found and conversely can prove
> things in an easily understandable way. If you understand graph
> theory and get an intermediate representation of some code, you
> are ready to do general (not target specific) optimisations.


Hmm, graph theory. I'll _definately_ have a look at this. It'll probably
be a big time saver for me since my spatial relationship abilities are
(supposedly) off the charts.

> I am not actually writing a traditional compiler but am involved
> in the optimisation of an intermediate representation of code;
> the output of the product is C.
> More about that only via PM and only as far as I am allowed to
> tell about it.


Well, you don't have to talk about that. I'm sure you've looked at other
stuff like:

GCC's RTL
TenDRA's ANDF
LCC's DAGs
Necula's CIL

So far, the only "C" compiler I've found that uses both a yacc and lex
grammar is Lutz Hamel's "C Subset Compiler" WCC for VMS.


Rod Pemberton


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
We dont give only job... We give you the Job Satisfaction....... Anuj Digital Photography 0 01-02-2007 06:35 PM
Give me some advice about some books of Java programing! yuyazhang Java 14 04-29-2006 11:13 AM
GIVE ME FILM OR GIVE ME DEATH l#vfgsgEg@AO1.com DVD Video 4 07-14-2005 03:10 PM
Give us 3 minutes; we give you the whole library lib Computer Support 1 02-04-2005 03:16 AM
Give us 3 minutes; we give you the whole library lib Computer Support 0 01-27-2005 07:52 AM



Advertisments