digitalmars.D.learn - Evaluating __FILE__ and __LINE__ of caller?
- H. S. Teoh (16/16) Mar 02 2012 Is it possible to get at the file and line number of where a function is
- Adam D. Ruppe (7/8) Mar 02 2012 Make that
- bioinfornatics (2/15) Mar 03 2012 I think __LINE__ is size_t not int
- Andrej Mitrovic (2/3) Mar 03 2012 I'd love to see a 2_147_483_648 line source file! :D
- Jonathan M Davis (4/20) Mar 03 2012 Yes, it's size_t.
- H. S. Teoh (9/13) Mar 03 2012 It *could* happen if the source file was auto-generated... and the
- Andrej Mitrovic (3/6) Mar 03 2012 It can be if you need an OOP D binding to a C/C++ library. E.g. QtD
- Jonathan M Davis (6/13) Mar 03 2012 All it takes is a function passing a size_t to that function rather than...
- Andrej Mitrovic (5/5) Mar 03 2012 Ok, well a quick search shows socket.d:132 needs fixing. Also there's
- Jonathan M Davis (5/10) Mar 03 2012 It's a common error to use int where size_t should be used. Using int wh...
Is it possible to get at the file and line number of where a function is being called from? For example: class A { int opIndex(int x) { /* do a bunch of checks */ if (checkFailed) throw new RangeError(...); /* compute value */ return value; } } I'd like to be able to throw the exception referencing the file/line of the caller, rather than opIndex() itself. Is this possible? T -- Two wrongs don't make a right; but three rights do make a left...
Mar 02 2012
On Saturday, 3 March 2012 at 01:36:51 UTC, H. S. Teoh wrote:int opIndex(int x) {Make that (int x, string file = __FILE__, int line = __LINE__) and use file/line in there. The exception consturctors do this, so you can throw new Exception("msg", file, line); and get it passed on.
Mar 02 2012
Le samedi 03 mars 2012 =C3=A0 02:39 +0100, Adam D. Ruppe a =C3=A9crit :On Saturday, 3 March 2012 at 01:36:51 UTC, H. S. Teoh wrote:I think __LINE__ is size_t not intint opIndex(int x) {=20 Make that =20 (int x, string file =3D __FILE__, int line =3D __LINE__) =20 and use file/line in there. The exception consturctors do this, so you can =20 throw new Exception("msg", file, line); =20 and get it passed on.
Mar 03 2012
On 3/3/12, bioinfornatics <bioinfornatics fedoraproject.org> wrote:I think __LINE__ is size_t not intI'd love to see a 2_147_483_648 line source file! :D
Mar 03 2012
On Saturday, March 03, 2012 13:21:05 bioinfornatics wrote:Le samedi 03 mars 2012 =C3=A0 02:39 +0100, Adam D. Ruppe a =C3=A9crit=:Yes, it's size_t. - Jonathan M DavisOn Saturday, 3 March 2012 at 01:36:51 UTC, H. S. Teoh wrote:=20 I think __LINE__ is size_t not int=09=09int opIndex(int x) {=20 Make that =20 (int x, string file =3D __FILE__, int line =3D __LINE__) =20 and use file/line in there. The exception consturctors do this, so you can =20 throw new Exception("msg", file, line); =20 and get it passed on.
Mar 03 2012
On Sat, Mar 03, 2012 at 03:52:55PM +0100, Andrej Mitrovic wrote:On 3/3/12, bioinfornatics <bioinfornatics fedoraproject.org> wrote:It *could* happen if the source file was auto-generated... and the autogenerator was broken. :P Of course, with D's templates, CTFE, and compile-time introspection capabilities, I can't imagine when autogeneration would actually be required, but we're talking about hypotheticals here. T -- Debian GNU/Linux: Cray on your desktop.I think __LINE__ is size_t not intI'd love to see a 2_147_483_648 line source file! :D
Mar 03 2012
On 3/3/12, H. S. Teoh <hsteoh quickfur.ath.cx> wrote:Of course, with D's templates, CTFE, and compile-time introspection capabilities, I can't imagine when autogeneration would actually be required, but we're talking about hypotheticals here.It can be if you need an OOP D binding to a C/C++ library. E.g. QtD uses an autogenerator, GtkD as well.
Mar 03 2012
On Saturday, March 03, 2012 23:01:38 Andrej Mitrovic wrote:On 3/3/12, H. S. Teoh <hsteoh quickfur.ath.cx> wrote:All it takes is a function passing a size_t to that function rather than letting it use its default value, and you'll get problems on 64-bit systems if you made the line number an int. It really needs to be a size_t, even if you'll never have a value for it which is high enough to need it. - Jonathan M DavisOf course, with D's templates, CTFE, and compile-time introspection capabilities, I can't imagine when autogeneration would actually be required, but we're talking about hypotheticals here.It can be if you need an OOP D binding to a C/C++ library. E.g. QtD uses an autogenerator, GtkD as well.
Mar 03 2012
Ok, well a quick search shows socket.d:132 needs fixing. Also there's two versioned out enforces in object_.d which use int line = __LINE__. Interestingly, earlier versions of Phobos used int a lot (I guess in pre-64bit compatible D days). I'm also seeing int used in Derelict, pspemu, plot2kill and dwt2.
Mar 03 2012
On Sunday, March 04, 2012 03:38:03 Andrej Mitrovic wrote:Ok, well a quick search shows socket.d:132 needs fixing. Also there's two versioned out enforces in object_.d which use int line = __LINE__. Interestingly, earlier versions of Phobos used int a lot (I guess in pre-64bit compatible D days). I'm also seeing int used in Derelict, pspemu, plot2kill and dwt2.It's a common error to use int where size_t should be used. Using int when dealing with __LINE__ is just one case of that. It didn't start actually causing compilation errors until we go 64-bit dmd though. - Jonathan M Davis
Mar 03 2012