 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Keith Thompson Guest
|
Posted: Fri Sep 29, 2006 9:11 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
Dave Thompson <david.thompson1 (AT) worldnet (DOT) att.net> writes:
| Quote: | On 18 Sep 2006 00:29:30 GMT, Allan Adler <ara (AT) nestle (DOT) csail.mit.edu
wrote:
[...]
warning: second parameter of va_start not last named argument
I'm ignoring it, since the program obviously works, but I'm
wondering whether there is some way to make the warning go away.
|
Yes, stop making the mistake that your compiler is warning you about.
| Quote: | As it says, invoke va_start using the last named (aka fixed) parameter
(not strictly speaking argument). This is the only way guaranteed to
work portably. If you specify any other parameter, it is possible for
the compiler to screw up by starting to look in the wrong place(s) for
the values of the varargs; if such code works on your compiler,
apparently it is ignoring what you wrote and using what it knows.
Especially since it labels this diagnostic as a warning; that usually
means it thinks it has corrected the problem -- but the implementor's
judgement/guess (far in advance) as to what you will have intended by
a given dubious construct can easily be mistaken.
|
Actually, I suspect that the compiler issues a warning rather than an
error not because it thinks it's corrected the problem, but because
the error is not a constraint violation. Based on the wording in the
standard (which could be clearer), passing something other than the
last named parameter to va_start() invokes undefined behavior. The
compiler is able to detect it and warn you about it, but it's not
going to reject the program because it's *conceivable* that the
programmer knows what he's doing.
It's like writing something like:
printf("%d\n", 1.0);
A sufficiently clever compiler will issue a warning but is unlikely to
reject the program, even though there's no significant chance that the
call is correct.
| Quote: | Commonly, like printf, there is only one named/fixed parm, so choosing
the right one is pretty easy.
|
Actually, I think printf is fairly unusual in having only one named
argument. Consider fprintf and sprintf.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) 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.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
WillerZ Guest
|
Posted: Fri Sep 29, 2006 9:11 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
Allan Adler wrote:
| Quote: | int vararg_inner_product(struct measured_list * ml, int f(),...)
^^^^^^^ |
Should be: int (*f)(int, int)
<snip>
| Quote: | va_start(ap,m);
^ change that to f |
That should sort you out...
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Fri Sep 29, 2006 9:11 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
Allan Adler <ara (AT) nestle (DOT) csail.mit.edu> writes:
| Quote: | Allan Adler <ara (AT) nestle (DOT) csail.mit.edu> writes:
In one case, there were two arguments followed by a variable argument list.
The first argument was a structure that contained, among other things, the
length of the variable argument list and the second argument was a pointer
to a function that gets called in the routine. The variable list of
arguments are all structs of the same type as the first argument. It
compiles and runs ok but I get the following complaint from the compiler:
warning: second parameter of va_start not last named argument
I'm ignoring it, since the program obviously works, but I'm
wondering whether there is some way to make the warning go away.
In response to requests for some actual code, I wrote another function
that has a similar description and produces the same warning, but which
is more easily taken out of its context. Here is the code (copied by hand):
which resides a file named scratch.c:
#include <stdio.h
#include <stdarg.h
struct measured_list {
int length_of_list;
int * list_of_int;
};
int vararg_inner_product(struct measured_list * ml, int f(),...)
{
va_list ap;
int i,j,k,m,n=0;
m = ml->length_of_list;
va_start(ap,m);
for(i=0;i<m;i++) {j=ml->list_of_int[i]; n += f(j,va_arg(ap,int));}
va_end(ap);
return n;
}
int mult(int a, int b) {return a*b;}
int mulist[5] = {3,1,4,1,6};
int main()
{
int i;
char c,d;
struct measured_list * myml; FILE * fp1, * fp2;
myml = (struct measured_list *) malloc(sizeof(struct measured_list));
myml->length_of_list = 5;
myml->list_of_int = mylist;
i = vararg_inner_product(myml,mult,2,7,1,8,2);
printf(i = %d\n",i);
return 0;
}
It prints i = 37 and the compiler warning is:
scratch.c: 14: warning: second parameter of 'va_start' not last
named argument
|
The code you posted doesn't even compile. You declare an array as
"mulist" and refer to it as "mylist". Your printf call is missing an
opening quotation mark.
You could easily have spent 5 minutes compiling your code and
correcting these errors before posting it. It is lazy and rude to
waste our time by failing to do so.
In your vararg_inner_product() function, you invoke va_start with a
second argument that is a local variable initialized with an
expression that depends on the functions' second-to-last named
argument. The *only* valid thing to use as the second argument to
va_start() is the last named parameter. Not the next-to-last named
parameter, not an expression based on something else -- just the last
named parameter. If you use anything else, you invoke undefined
behavior.
As always, one possible consequence of undefined behavior is that your
program works exactly as you want it to. Another possible consequence
is that it works exactly as you want it to during testing, and fails
catastrophically at the most inconvenient possible moment.
You have been told this several times, by people who know what they're
talking about, yet you persist in failing to correct the bug. Why?
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) 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.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Allan Adler Guest
|
Posted: Wed Oct 04, 2006 2:44 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
WillerZ <newsreplies (AT) willerz (DOT) org> writes:
| Quote: | Allan Adler wrote:
int vararg_inner_product(struct measured_list * ml, int f(),...)
^^^^^^^
Should be: int (*f)(int, int)
snip
va_start(ap,m);
^ change that to f
That should sort you out...
|
Thanks very much for your help with this. So far, WillerZ is unique, among
respondents to my questions, in having actually patiently explained in detail
where the errors were in my code and exactly how to fix them. I really didn't
understand that the m had to be an f because, in the books I am using for C,
the use of varargs is not really explained, only presented in a form that
invites monkey-see-monkey-do approaches without any genuine insight or
understanding and the kind of thing I was trying to do here was not one
of the things the monkey had seen before.
--
Ignorantly,
Allan Adler <ara (AT) zurich (DOT) csail.mit.edu>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Allan Adler Guest
|
Posted: Wed Oct 04, 2006 2:44 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
Allan Adler <ara (AT) nestle (DOT) csail.mit.edu> writes:
| Quote: | int vararg_inner_product(struct measured_list * ml, int f(),...)
{
va_list ap;
int i,j,k,m,n=0;
m = ml->length_of_list;
va_start(ap,m);
for(i=0;i<m;i++) {j=ml->list_of_int[i]; n += f(j,va_arg(ap,int));}
va_end(ap);
return n;
}
|
The thing I never understood, but I think I understand now, is that the
compiler has to be told where the list of variable arguments starts. I had
thought, incorrectly:
(1) the compiler already knows where the list of variable arguments starts,
since it is clearly marked by the ... in the argument list;
(2) the only thing it needs to know, therefore, is the number of variable
arguments.
In the case of sum(int no_summands,...), for example, the code would
contain va_start(ap,no_summands), and this was typical of the examples
I had seen worked out in detail. Thus, it was natural, especially in view
of (2), to suppose that what had to be the second argument of va_start was
the number of arguments. And that's why I wrote m as the second argument
in my code.
Now that I know how it is supposed to be done, thanks to WillerZ's explicitly
telling me to change the m to an f, I've reread the description of the
varargs facility in my old copy of Harbison and Steele. I've always found
it incomprehensible, but now that I know what he is talking about, it makes
perfect sense. The one example they present in detail is vulnerable to
precisely the misunderstanding I articulated above. When the compiler warning
(echoed by some respondents) merely says to make the second argument of
va_start the same as the last named argument of the ambient routine (which
could have equally well meant changing the f to an m, or perhaps something
entirely different from both possibilities), it doesn't say why. Of course,
neither the compiler nor other respondents could have known what exactly
I was confused about, and neither did I, since I was confused and didn't
know I was confused about that point. But now all is clear and I am very
grateful for all the help. This was an important misconception on my part
and I'm very happy about finally (I hope) understanding correctly.
One thing I would like to know is whether there is any book on C that
provides detailed examples of the use of the vararg facility that make
the precise misunderstanding I mentioned above impossible, apart from
merely saying in prose that the second argument to va_start is the last
last fixed argument of the routine?
--
Ignorantly,
Allan Adler <ara (AT) zurich (DOT) csail.mit.edu>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
CBFalconer Guest
|
Posted: Thu Oct 05, 2006 9:11 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
Allan Adler wrote:
| Quote: |
..... snip ...
One thing I would like to know is whether there is any book on C that
provides detailed examples of the use of the vararg facility that
make the precise misunderstanding I mentioned above impossible, apart
from merely saying in prose that the second argument to va_start is
the last last fixed argument of the routine?
|
I don't know about that, but I do know that using a variadic
function is an invitation for gross errors in C. The reason is
that such usage will normally avoid all parameter type and number
checking.
--
Some informative links:
<news:news.announce.newusers
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Douglas A. Gwyn Guest
|
Posted: Sun Oct 08, 2006 4:46 am Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
CBFalconer wrote:
| Quote: | I don't know about that, but I do know that using a variadic
function is an invitation for gross errors in C. The reason is
that such usage will normally avoid all parameter type and number
checking.
|
The main practical use of variadic functions in C seems to be
for printf-like error logging functions. Many versions of
"lint" support an embedded notation like /*PRINTFLIKEn*/ so
that the first n-1 arguments are checked normally and the nth
argument is treated as a printf-like format string which is
checked against the types of the following arguments. That
helps catch a class of errors earlier than might happen
otherwise.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
jasen Guest
|
Posted: Fri Oct 13, 2006 9:19 pm Post subject: Re: sum(2,4,3,5,-1,...) |
|
|
On 2006-10-07, Douglas A. Gwyn <DAGwyn (AT) null (DOT) net> wrote:
| Quote: | CBFalconer wrote:
I don't know about that, but I do know that using a variadic
function is an invitation for gross errors in C. The reason is
that such usage will normally avoid all parameter type and number
checking.
The main practical use of variadic functions in C seems to be
for printf-like error logging functions. Many versions of
"lint" support an embedded notation like /*PRINTFLIKEn*/ so
that the first n-1 arguments are checked normally and the nth
argument is treated as a printf-like format string which is
checked against the types of the following arguments.
|
gcc has a similar feature built in using __attribute__ format
eg:
extern int
my_printf (void *my_object, const char *my_format, ...)
__attribute__ ((format (printf, 2, 3)));
| Quote: | That helps catch a class of errors earlier than might happen
otherwise.
|
indeed.
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
WillerZ Guest
|
Posted: Sat Nov 11, 2006 5:38 am Post subject: Re: structure and file |
|
|
sree10784 (AT) gmail (DOT) com wrote:
<snip>
| Quote: | can any one correct it
|
Yes. I wanted to be sure my answer was as useful as your question, so I
took the time to eliminate all the extraneous information.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Kenneth Brody Guest
|
Posted: Sat Nov 11, 2006 6:19 am Post subject: Re: structure and file |
|
|
sree10784 (AT) gmail (DOT) com wrote:
| Quote: |
#include<stdio.h
[... snip uncommented source code ...]
}
can any one correct it
|
What's broken? (Besides the obvious, that is.) What is it doing
that it's not supposed to? Or, what is it not doing that it is
supposed to do?
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap (AT) gmail (DOT) com>
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
onkar Guest
|
Posted: Wed Nov 15, 2006 10:11 am Post subject: Re: structure and file |
|
|
#include<stdio.h>
//#include<conio.h>
# include "malloc.h"
/* add_book();
delete_book();
add_user();
delete_user();
book_issue();
book_return();
close_app(); */
void book_read(struct book **);
void display(struct book *);
/* void user_read(struct user **);
void transaction_read(struct transaction **); */
struct book
{
int book_id;
char book_title[100];
char book_author[100];
struct book * book_link;
};
/*struct user
{
int user_id;
char user_name[100];
char user_type;
int no_of_books_taken;
struct user *user_link;
};
struct transaction
{
int tran_book_id;
int tran_user_id;
struct transaction * transaction_link;
}; */
void main()
{
struct book * book_ptr;
/* struct user * user_ptr;
struct transaction * transaction_ptr;
int choice; */
book_ptr = NULL;
/* user_ptr = NULL;
transaction_ptr = NULL; */
book_read(&book_ptr);
display(book_ptr);
/* user_read(&user_ptr);
transaction_read(&transaction_ptr);
printf("1.Add book\n");
printf("2.Delete book\n");
printf("3.Add user\n");
printf("4.Delete user\n");
printf("5.Issue book\n");
printf("6.Return book\n");
printf("7.Close the application")
printf("enter your choice\n");
scanf("%d",choice);
switch (choice)
{
default :
printf("Invalid choice.Please enter the choice again");
case 1 :
{
add_book();
break;
}
case 2 :
{
delete_book();
break;
}
case 3 :
{
add_user();
break;
}
case 4 :
{
delete_user();
break;
}
case 5:
{
book_issue();
break;
}
case 6 :
{
book_return();
break;
}
case 7 :
{
close_app();
break;
}
} */
}
void book_read(struct book **temp)
{
struct book * buffer , *temp_1 = *temp;
FILE * fptr;
fptr=fopen("D:\sree\case study\res.txt","r");
buffer = (struct book * ) malloc ( sizeof(struct book));
while((fscanf(fptr,"%d %s\
%s",&(buffer->book_id),buffer->book_title,buffer->book_author))!=EOF)
{
if ((*temp)=NULL)
{
*temp=buffer;
((*temp)->book_link)=temp_1;
buffer = (struct book * ) malloc(sizeof (struct
book));
}
else
{
while (temp_1 != NULL)
temp_1 = ((temp_1)->book_link);
(buffer->book_link) = ((temp_1)->book_link);
temp_1->book_link = buffer;
buffer = (struct book * ) malloc(sizeof (struct
book));
}
}
}
void display(struct book *pt)
{
while(pt!=NULL){
printf(" Data
:%d\t%s\t%s",pt->book_id,pt->book_title,pt->book_author);
pt=pt->book_link;
}
}
compiled on GNU/Linux worked well .. remove the comments //#include
conio.h
sree10784 (AT) gmail (DOT) com wrote:
| Quote: | #include<stdio.h
#include<conio.h
# include "malloc.h"
/* add_book();
delete_book();
add_user();
delete_user();
book_issue();
book_return();
close_app(); */
void book_read(struct book **);
void display(struct book *);
/* void user_read(struct user **);
void transaction_read(struct transaction **); */
struct book
{
int book_id;
char book_title[100];
char book_author[100];
struct book * book_link;
};
/*struct user
{
int user_id;
char user_name[100];
char user_type;
int no_of_books_taken;
struct user *user_link;
};
struct transaction
{
int tran_book_id;
int tran_user_id;
struct transaction * transaction_link;
}; */
void main()
{
struct book * book_ptr;
/* struct user * user_ptr;
struct transaction * transaction_ptr;
int choice; */
book_ptr = NULL;
/* user_ptr = NULL;
transaction_ptr = NULL; */
book_read(&book_ptr);
display(book_ptr);
/* user_read(&user_ptr);
transaction_read(&transaction_ptr);
printf("1.Add book\n");
printf("2.Delete book\n");
printf("3.Add user\n");
printf("4.Delete user\n");
printf("5.Issue book\n");
printf("6.Return book\n");
printf("7.Close the application")
printf("enter your choice\n");
scanf("%d",choice);
switch (choice)
{
default :
printf("Invalid choice.Please enter the choice again");
case 1 :
{
add_book();
break;
}
case 2 :
{
delete_book();
break;
}
case 3 :
{
add_user();
break;
}
case 4 :
{
delete_user();
break;
}
case 5:
{
book_issue();
break;
}
case 6 :
{
book_return();
break;
}
case 7 :
{
close_app();
break;
}
} */
}
void book_read(struct book **temp)
{
struct book * buffer , *temp_1 = *temp;
FILE * fptr;
fptr=fopen("D:\sree\case study\res.txt","r");
buffer = (struct book * ) malloc ( sizeof(struct book));
while((fscanf(fptr,"%d %s
%s",&(buffer->book_id),buffer->book_title,buffer->book_author))!=EOF)
{
if ((*temp)=NULL)
{
*temp=buffer;
((*temp)->book_link)=temp_1;
buffer = (struct book * ) malloc(sizeof (struct book));
}
else
{
while (temp_1 != NULL)
temp_1 = ((temp_1)->book_link);
(buffer->book_link) = ((temp_1)->book_link);
temp_1->book_link = buffer;
buffer = (struct book * ) malloc(sizeof (struct book));
}
}
}
void display(struct book *pt)
{
while(pt!=NULL)
{
printf(" Data :
%d\t%s\t%s",pt->book_id,pt->book_title,pt->book_author);
pt=pt->book_link;
}
}
can any one correct it
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
-- |
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
santosh Guest
|
Posted: Wed Dec 06, 2006 1:55 am Post subject: Re: How to become C expert? |
|
|
the_i...@yahoo.co.in wrote:
| Quote: | Hi friends,
I am very new to C, please tell me how to become C Expert.
How to start,
|
Practise is the only realistic way to become proficient in any skill.
That's true for C too. Write a lot of test programs, try to finish
small projects like a calculator program etc.
| Quote: | What books to refer,
|
If you can get it, acquire The C Programming Language 2nd Edition by
Kernighan & Ritchie.
Also look over general programming books like Code Complete etc.
| Quote: | how to think in C( sounds idiotic, but any suggestion will be helpful)
|
If you can think logically and attack a problem by the policy of divide
and conquer, then, for the most part, you're already thinking in C.
| Quote: | and do I have to know the working of compiler to become C expert.
|
Not now. That'll come _much_ later. And yes, it's always a useful
skill, particularly if you want to design and implement your own
language.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Walter Roberson Guest
|
Posted: Wed Dec 06, 2006 1:55 am Post subject: Re: How to become C expert? |
|
|
In article <1164910898.916499.243760 (AT) n67g2000cwd (DOT) googlegroups.com>,
<the_init (AT) yahoo (DOT) co.in> wrote:
| Quote: | I am very new to C, please tell me how to become C Expert.
|
"The road to wisdom? Well, it's plain & simple to express,
Err and err and err again, but less and less and less."
-- Piet Hein
--
Prototypes are supertypes of their clones. -- maplesoft
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Eric Sosman Guest
|
Posted: Wed Dec 06, 2006 1:55 am Post subject: Re: How to become C expert? |
|
|
the_init (AT) yahoo (DOT) co.in wrote:
| Quote: | Hi friends,
I am very new to C, please tell me how to become C Expert.
|
I don't know. I started learning C thirty years ago, and
I am still learning. I consider myself "competent," but not
"expert." I doubt I will ever consider myself "expert."
| Quote: | How to start,
What books to refer,
|
The best C book I read was also the first: "The C Programming
Language" by Kernighan and Ritchie. It was not a programming text,
but an introduction to C for people who already knew how to write
programs in three or four other languages. If that describes you,
"K&R" is hard to beat.
I'm told that K&R have since issued a second edition of "TCPL"
that describes the version of C that emerged from the process
culminating in the 1989 ANSI C Standard (more or less; the book
apparently came out before the Standard did, and necesarily missed
some of the last-minute changes). I have not, myself, read this
second edition, but others speak highly of it.
| Quote: | how to think in C( sounds idiotic, but any suggestion will be helpful)
|
My recipe for getting started with a new programming language
has always been the same, and has always worked -- for me, anyhow.
First, read The Book (there is always a Book of some kind). You
will not understand all that you read on the first pass, but read
it anyhow. Next, write a few trivial programs -- in C there is a
tradition about writing a program that outputs "Hello, world!", but
I usually choose the Eight Queens problem. Then, with The Book at
your elbow, start reading a medium-sized program written by some
good programmers well-steeped in the language you're learning. Much
of what you see will be baffling -- Why did they do *that*? -- but
by consulting The Book you will at least understand the effect if
not the rationale. Then write a few non-trivial programs, then start
reading larger programs written by others, and so on. When you really
think you're getting somewhere, pick up a *huge* program whose sheer
size defeats any hope of a Gestalt understanding, and try to add
something to it: This helps with the valuable skill of reasoning
from incomplete information.
| Quote: | and do I have to know the working of compiler to become C expert.
|
No, no more than you have to be a fuel combustion engineer to
drive an automobile.
--
Eric Sosman
esosman@acm-dot-org.invalid
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
MQ Guest
|
Posted: Wed Dec 06, 2006 1:55 am Post subject: Re: How to become C expert? |
|
|
the_init (AT) yahoo (DOT) co.in wrote:
| Quote: | Hi friends,
I am very new to C, please tell me how to become C Expert.
How to start,
What books to refer,
how to think in C( sounds idiotic, but any suggestion will be helpful)
|
Buy a good book on C, which also covers aspects of program design. Use
Google. There's heaps
of info out there. Write some programs...
| Quote: |
and do I have to know the working of compiler to become C expert.
|
You don't need to know the internal working of the compiler, only how
to use the compiler. The compiler is necessary to create a program
from C source code.
MQ
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|