Skip to content

Deprecate __LINE__ and __FILE__ #1068

Closed
@Rangi42

Description

@Rangi42

The advantage of these constants in C is that they're not affected by macros, so you can have a "utilities.h":

#define crash(msg) exit((fprintf(stderr, "%s(%d): %s", __FILE__, __LINE__, msg), 1))

And then crash("oops"); on line 42 of main.c will print "main.c(42): oops", not "utilities.h(6): oops".

On the other hand, rgbasm does not work like that. __FILE__ and __LINE__ use their deepest context in the fstack of include, rept, and macro nodes. So they're only useful for local reporting, but then, you already know what line you're on when you write them.

If anything, it would be more useful to expose other dynamic information. Such as the current section name, which #1066 would allow with SECTION(@). Or the current "label scope", a concept which is mentioned in rgbasm(5) but not currently accessible. (Similar to __func__ in C99, or __FUNCTION__ in gcc prior to that.) That would let you do this in utilities.inc:

MACRO error
    FAIL STRFMT("In section \"%s\", label %s: %s", SECTION(@), __LABELSCOPE__, \1)
ENDM

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementTypically new features; lesser priority than bugsrgbasmThis affects RGBASM

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions