C Error Line Number
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company c __line__ Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs c++ exception line number Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers,
__file__
just like you, helping each other. Join them; it only takes a minute: Sign up Exact line number for C error? up vote 1 down vote favorite I have a compiled version of the game 'Rogue', as
Fprintf
well as its source code. Sometimes, at seemingly random times, the game will put up a non-descriptive error message. Is there a way of compiling the source in an IDE, and getting the specific line number where the program fails when it is run in the IDE? c share|improve this question edited Jan 17 '12 at 8:24 BЈовић 36.3k2398174 asked Jan 16 '12 at 18:21 Connor Nicholson 61 As you have the sprintf source, if it is built with a "source database" then there will be ways to debug the source of the error. We would need to know more info, e.g. what platform you are running on, what compiler is building and what tools you have in mind. –CashCow Jan 16 '12 at 18:24 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote If you can edit the error messages to: printf (stderr, "Blah error at %s (%d)\n", __FILE__, __LINE__); you can get the exact location. Since editing all the messages would be a big pain, I'd suggest you define a macro that does it: #define MYERR(...) do { \ printf ("@ %s (%d): ", __FILE__, __LINE__); \ printf (__VA_ARGS__); \ } while (0) Replace all error messages calls to invoke this macro (thats much easier than appending to each message). share|improve this answer edited Jan 16 '12 at 20:19 answered Jan 16 '12 at 18:35 jman 7,81142150 Note that the line number can be redefined with the #line preprocessor directive, so "exact location" is not always correct. –William Pursell Jan 16 '12 at 23:21 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Ascii Table
policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a http://stackoverflow.com/questions/8884481/exact-line-number-for-c-error minute: Sign up C/C++ line number up vote 68 down vote favorite 25 In the sake of debugging purposes, can I get the line number in C/C++ compilers? (standard way or specific ways for certain compilers) e.g if(!Logical) printf("Not logical value at line number %d \n",LineNumber); // How to get LineNumber without writing it by my hand?(dynamic compilation) c++ c c-preprocessor http://stackoverflow.com/questions/2849832/c-c-line-number line-numbers dynamic-compilation share|improve this question edited Feb 24 at 17:33 Brian Tompsett - 汤莱恩 3,083112675 asked May 17 '10 at 14:25 Betamoo 4,963134497 2 Why don't you use a debugger? –Lucas May 17 '10 at 14:27 15 @Lucas: Some of us prefer not to mess with debuggers. This kind of "poor person's assert statement" is sometimes more clear because it's a permanent part of the code, and enduring documentation of things that should be true about the state of the computation. –S.Lott May 17 '10 at 14:36 11 @Lucas: Debuggers are also less than useful for intermittent problems in long-running programs, or for collecting information about problems in software deployed at client sites. In these cases, the only option is for the program to log as much information about the state of the program as possible, for later analysis. –KeithB May 17 '10 at 14:59 @Lucas And debuggers don't work so well on some embedded systems to get this information. –George Stocker♦ Dec 10 '15 at 14:08 add a comment| 7 Answers 7 active oldest votes up
Login: [x] User account creation filtered due to spam. Bug57950 - wrong line numbers in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57950 error messages for inline assembler statements Summary: wrong line numbers in https://root.cern.ch/phpBB3/viewtopic.php?t=4808 error messages for inline assembler statements Status: UNCONFIRMED Alias: None Product: gcc Classification: Unclassified Component: inline-asm (show other bugs) Version: 4.7.2 Importance: P3 normal Target Milestone: --- Assignee: Not yet assigned to anyone URL: Keywords: Depends on: Blocks: Reported: 2013-07-21 19:16 UTC by line number Frank Heckenbach Modified: 2016-06-23 10:48 UTC (History) CC List: 2 users (show) dmalcolm manu See Also: Host: Target: Build: Known to work: Known to fail: Last reconfirmed: Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Frank Heckenbach 2013-07-21 c error line 19:16:15 UTC This was reported as Debian bug #588087 several years ago ... For error messages concerning inline assembler statements, gcc counts embedded "\n" characters towards the line number, instead of actual newlines in the source file, so the error messages refer to the wrong lines. Compiling the test program below with "gcc asm-line-number.c" gives this output: asm-line-number.c: Assembler messages: asm-line-number.c:3: Error: no such instruction: `foo' asm-line-number.c:4: Error: no such instruction: `foo' asm-line-number.c:8: Error: no such instruction: `foo' In f1(), both asm errors are in the same source line (3), but gcc counts them as different because of the "\n" between them. In f2(), the line number refers to the line (8) which contains "__asm__" instead of the line (10) with the actual asm code. static void f1 () { __asm__ ("foo\nfoo"); } static void f2 () { __asm__ ( "foo" ); } Comment 1 Andrew Pinski 2013-07-21 20:19:09 UTC It is not GCC which is reporting this error message but rather gas (binutils) tho
/ warning messages Discuss installing and running CINT here. Please post bug reports here. Moderator: cintdev Post Reply Search Advanced search First unread post • 2 posts • Page 1 of 1 cthies Posts: 3 Joined: Thu Apr 19, 2007 11:35 Incomprehensible line numbers in error / warning messages Quote Unread postby cthies » Fri Apr 20, 2007 13:30 Hi, When running cint macros using loops with blocks in curled brackets the line numbering in my root installataion is somehow incomprehensible. The line numbers indicated in the error/warning output of cint do not correspond with the actual line numbering in the source file. And i did not find any hint on this in the documentation until now. The following code sample illustrates this effect. int TEST () { for (int i = 0; i < 4; i++){ printf("Hello1\n"); printf("Hello2\n"); }; ERROR (); return 10; }; if runing that bit of code in my installation I get the following output. root [1] .x TEST.C Hello1 Hello2 Hello1 Hello2 Hello1 Hello2 Hello1 Hello2 Error: Function ERROR() is not defined in current scope TEST.C:11: *** Interpreter error recovered *** Here the error line number is given with 11 but the undefined function ERROR is located in line 9. After some tests i got the impression that the scope of the for-loop indicated by the curly brackets seems to confuse cint in some way. I am interested if i made a mistake in the installation and if so how to fix it. Thanks Christian Top pcanal Posts: 6977 Joined: Wed Aug 27, 2003 15:22 Location: Fermilab Quote Unread postby pcanal » Fri Apr 20, 2007 18:37 Hi, The error message issued by CINT are known to be sometimes somewhat inaccurate and/or hard to decipher. We do plan on improving the situation. We are currently working on revamping the CINT code base when this is done (hopefully soon) we would be in a better position to address those kind of issues). In the meantime, whenever seeing a 'weird' CINT error message, I recommend to ask the compiler for a better diagnosis by simply using ACLiC:Code: Select allroot [2] .L TEST.C