Path: utzoo!attcan!uunet!mcsun!hp4nl!star.cs.vu.nl!condict From: condict@cs.vu.nl (Michael Condict) Newsgroups: comp.lang.c Subject: Re: __LINE__ and __FILE__ -- a beginner's question Message-ID: <3723@condict.cs.vu.nl> Date: 16 Oct 89 08:10:45 GMT References: <6257@arcturus> Reply-To: condict@cs.vu.nl (Michael Condict) Organization: VU Informatica, Amsterdam Lines: 22 In article <6257@arcturus> evil@arcturus.UUCP (Wade Guthrie) writes: >For what purpose are the __LINE__ and __FILE__ macros used? Are these >only useful for the writers of code that, in turn, produces compileable >code, or is there some use for the applications programmer? My favorite use in application programs is in the definition of a debugging macro that, given a Boolean expression, evaluates it and reports an error message if false. (It usually also does something drastic like intentionally dumping core.) The __LINE__ and __FILE__ vars provide a handy way to report a uniquely identify which assertion failed. Example: #define ASSERT(b) \ if (!b) { fprintf(stderr, "Assertion violated in %s, line %d. Goodbye.\n", __FILE__, __LINE__); abort(); } Michael Condict Vrije University Amsterdam