LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-20-2005, 02:21 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Rep: Reputation: 45
gnu error format


Hi i have found the following text to the gnu coding manual


Quote:
4.3 Formatting Error Messages

Error messages from compilers should look like this:

source-file-name:lineno: message
Do u know how i can print the line that created the error?
 
Old 08-20-2005, 02:45 AM   #2
sind
Member
 
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
The GNU C preprocessor will expand __FILE__ and __LINE__ in your source files to the filename, ie "test.c" (as a string), and the line number (as an integer), respectively.

So you could have something like this:

Code:
fprintf(stderr, "%s: %d: error\n", __FILE__, __LINE__);
That won't show you the line that caused the error, but it should help you find that line more easily.

~sind
 
Old 08-20-2005, 02:58 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Thx a lot really
 
Old 08-21-2005, 10:36 AM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Thx a lot i have tried that but as we can easily understand cant work
perror("Please check the %s : %d \n",__FILE__,__LINE__);
Do u have something to suggest me so as to provide this functionality to my site
 
Old 08-21-2005, 11:09 PM   #5
sind
Member
 
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
AFAIK, perror() does not support format strings. You can use fprintf() to stderr with strerror() to acheive the same result as perror(), while being able to use format strings.

For example:

Code:
fprintf(stderr, "%s: %d: %s\n", __FILE__, __LINE__, strerror(errno));
~sind
 
Old 08-21-2005, 11:27 PM   #6
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Thx really for your time
strerror(errno)) prints exactly the same message with perror right?
I ll check it later... thanx a lot
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format error Gimmick Mandriva 2 07-13-2005 09:23 PM
QMAIL error:554 Transaction failed: message format error mpk25 Linux - Software 1 10-15-2004 12:53 PM
MDK 9.1 Fatal Error in Stage 1: Exec Format Error Beano Mandriva 5 09-12-2004 03:04 PM
mozilla-i686-pc-linux-gnu-1.4-koKR.tar.gz install error.. eye Linux - Software 1 09-01-2003 01:48 AM
GNU libc libraries error Kaotica Linux - Software 1 04-16-2003 04:56 AM


All times are GMT -5. The time now is 04:52 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
Open Source Consulting | Domain Registration