LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxAnswers Discussion
User Name
Password
LinuxAnswers Discussion This forum is to discuss articles posted to LinuxAnswers.

Notices

Reply
 
Search this Thread
Old 06-29-2009, 03:28 PM   #16
JimHughen
Member
 
Registered: Jun 2009
Location: Austin, Texas
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 16
Unhappy local variable initialition


The local variable szNewString[] is not initialized.

On Cygwin, there was trash in front of the printed string.

Seems like it would always be the case. I would not think
the compiler could take the initiative to initialize my
local variables. If it did, it might take unnecessary
execution time. Even if it did, the author should not
leave these uninitialized.

I added:

Code:
  char szNewString[SIZE];

  szNewString[0] = '\0';
Uninitialized variables can be the source of many bugs...
 
Old 10-17-2009, 08:05 PM   #17
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Rep: Reputation: Disabled
More Problems with the C Code in this Tutorial

When I compile "cc -c appendall.c" under Fedora11 with all the defaults, I get an error complaining that there are, "incompatible implicit declarations of built-in functions" strcat and strlen.

The offending lines have the code:

strlen( szReturnBuffer ) + strlen( iArgs[i] )

and:

strcat( szReturnBuffer, iArgs[i] )

Now since these variables are declared as char * iArgs[] and
char * szReturnBuffer, these errors look simply wrong, unless the detault is so pedantic a version that it won't tolerate interchange of arrays and pointers in this context.

But what is the problem really, here?

Just in case the reader does not remember the defaults for Fedora11, gcc version displays:

gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
 
Old 10-19-2009, 01:15 PM   #18
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Rep: Reputation: Disabled
Information Hiding

Quote:
Originally Posted by kumar.anupam View Post
where does the temporary variables gets stored while executing C program.
By design, the C programmer usually does not need to know the answer to this question. This is an example of the principle called "information hiding", a principle very basic to all object oriented programming, though it actually predates OOP.

However, the usual place for such data is on the stack: most modern CPU architectures make it easy to store lots of variables on the same stack used for return addresses. Just don't make them TOO big!

Then again, a few temporary variables may actually get stored in CPU registers. But this is an optimization, so it is highly dependent on 1) what level of optimization you compile for and 2) the code generator of your compiler.

Again, by design, the programmer does not need to know. Except possibly for very special purposes, such as optimization.
 
Old 10-19-2009, 01:17 PM   #19
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Rep: Reputation: Disabled
Quote:
Originally Posted by mejohnsn View Post
When I compile "cc -c appendall.c" under Fedora11 with all the defaults, I get an error complaining that there are, "incompatible implicit declarations of built-in functions" strcat and strlen.

The offending lines have the code:

strlen( szReturnBuffer ) + strlen( iArgs[i] )

and:

strcat( szReturnBuffer, iArgs[i] )

Now since these variables are declared as char * iArgs[] and
char * szReturnBuffer, these errors look simply wrong, unless the detault is so pedantic a version that it won't tolerate interchange of arrays and pointers in this context.

But what is the problem really, here?

Just in case the reader does not remember the defaults for Fedora11, gcc version displays:

gcc (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
It turns out the problem is that the program omitted a vital #include: somewhere near the top there should be "#include <string.h>". What version of C or of <stdio.h> was the author using that it already included the right declaration for strlen and strcat? This is NOT standard.
 
Old 04-02-2010, 02:02 AM   #20
akshat01
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: Disabled
well this is my first post on this forum.. and my sole purpose of joining it was tht to learn c programming in linux!!! can any1 gimme a link or a tutorial to start from basic's of difference between linux and winodws programming!!

im new to the world of c programming !!! and have jus started wid the basics of c.. wanna learn together in linux also !!!
 
Old 05-18-2010, 12:11 PM   #21
urrohit
LQ Newbie
 
Registered: Mar 2010
Posts: 21

Rep: Reputation: 0
Thumbs up got more knowledge

thanks for this one ..
got to know more about ,make file and
i cleared some of my doubts
 
Old 05-27-2010, 07:37 PM   #22
rmknox
Member
 
Registered: May 2010
Posts: 351

Rep: Reputation: 29
Fantastic

Exactly what I was looking for.
I was lost in a world of compiler and linker option switches and where the .h files were located and never guessed that it was all known to the system.

I have umpteen years of experience but it's 20 years since I used unix and really very limited Intel experience.

Anyway thanks so much
 
Old 07-09-2010, 01:55 AM   #23
lalithasankh
LQ Newbie
 
Registered: May 2010
Posts: 28

Rep: Reputation: 15
need help for use of termios in linux

I want to read data from serial port without using carriage return
please tell me how to do it
 
Old 08-18-2010, 09:38 AM   #24
PavelMdr
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
Thumbs up

Je to super. Zacinam l linuxmandrake a super. Diky moc za názorna témata
 
Old 08-19-2010, 09:05 AM   #25
milindlokde
Member
 
Registered: Apr 2007
Location: Mumbai, India
Distribution: Fedora, ubuntu
Posts: 119

Rep: Reputation: 21
Good tutorial. Most source codes are too large for a beginner. I never knew how to create a makefile. The tutorial is missing 'configure' script an important part of most *nix source codes.
 
Old 11-06-2011, 07:52 PM   #26
mikeeve
LQ Newbie
 
Registered: Nov 2011
Location: Washington State
Distribution: Mint
Posts: 2

Rep: Reputation: Disabled
Thumbs down Not a good tutorial

This is my first post, and I must be negative. I did extensive C programming 20 years ago, and typed in the appendall source code as entered. As others have commented, this code has several errors: missing include file statements and uninitialized strings. Maybe there is now a hand-holding compiler that can make sense of this code, but the example does not work using gcc/Ubuntu. This could be a very discouraging experience for a novice. The tutorial should either be corrected or removed.
 
Old 10-16-2012, 11:53 PM   #27
suttiwit
Member
 
Registered: Aug 2012
Location: Chiang Mai, Thailand
Distribution: Kubuntu 12.10 x86_64
Posts: 192
Blog Entries: 2

Rep: Reputation: 22
Code:
#include <stdio.h>

int main(void)
{
     typedef int hello;
     hello world;
     return 0;
}

Last edited by suttiwit; 10-16-2012 at 11:59 PM.
 
Old 09-04-2013, 09:36 AM   #28
vikram015
LQ Newbie
 
Registered: Nov 2012
Posts: 3

Rep: Reputation: Disabled
is there any way to send an email using c program

without using any library or application
if it is please send me at
vikram5909015@gmail.com
 
Old 09-04-2013, 09:59 AM   #29
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,282

Rep: Reputation: 172Reputation: 172
anything else you need doing? now you have our attention.

shame to waste all this talent.
Maybe you should compile a list of what you need doing.
 
Old 09-04-2013, 10:19 AM   #30
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,479

Rep: Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220Reputation: 1220
Quote:
Originally Posted by crabboy View Post
This thread is to discuss the article titled: Building C programs on Linux
this tutorial is perfect, the only problem is that it is only the very first step. Creating a professional build system needs a lot more (including a few years of practice)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DISCUSSION: Building C++ programs on Linux hylke LinuxAnswers Discussion 32 10-03-2013 09:27 AM
DISCUSSION: Building a Slackware Wireless Access Point eric.r.turner LinuxAnswers Discussion 11 09-09-2006 01:36 AM
DISCUSSION: ssh w/ gtk programs (host-client display export) mrchaos LinuxAnswers Discussion 1 12-14-2005 01:50 PM
DISCUSSION: Compiling Programs from Source jeremy LinuxAnswers Discussion 51 11-21-2005 04:35 AM
DISCUSSION: Virtual Filesystem: Building a Linux Filesystem from an Ordinary File mchirico LinuxAnswers Discussion 0 10-28-2004 10:35 PM


All times are GMT -5. The time now is 09:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration