This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New GCC extension hint


Hello.
I have got an idea that could become a good GNU extension.
It is similar to __FUNCTION__ and __PRETTY_FUNCTION__.
I have came to this because of debuging where it could be very
useful and because it is not possible to solve it as macro.



Main idea is this:

__VALUE__(var, style)

Where __VALUE__ acts like macro that examines variable "var"
and returns styled string.



For example, source code like this:

struct foo {
    int a;
    bool b;
    char c[248];
} bar;

int main() {
    bar.a = 10;
    bar.b = true;
    strcpy(c,"Something");

    printf("Status 1:\n%s\n\n",__VALUE__(bar,default));
    printf("Status 2:\n%s\n\n",__VALUE__(bar.a,default));
    printf("Status 3:\n%s\n\n",__VALUE__(bar.c[1],default));

    return 0;
}

...Would output this:

Status 1:
bar:
    a = 10
    b = true
    c = Something


Status 2:
bar.a = 10

Status 3:
bar.c[1] = o




There should be different styles of output for different types.

Suggested styles:
(These styles are only an idea. I know that especially c and cpp styles are
 not exactly what is it meant to be. )


default - would be one of style bellow
normal  - would output normally "variable name = variable value"
c       - would add brackets, quotes and semicolons for string to look C -styled
cpp     - would add brackets, quotes and semicolons for string to look C++ -styled

There could be another styles like:
asm, fortran, f77, basic

Or additional styles like:
aligned (to align first value characters),
tabbed (to use \t character instead of spaces)



Example of output using "cpp" style:

Status 1:
struct bar = {
    int a = 10;
    bool b = true;
    char *c = "Something";
}

Status 2:
int bar.a = 10;

Status 3:
char bar.c[1] = 'o';




My idea of implementation (short I know):

char *__VALUE__(val, style) {
    char *sz = alloc( requested bytes );
    sprintf(sz, GENERATED_STYLE_STRING, val, ...);
    free_when_leaving_block( sz );
    return sz;
};




I think impliementing something like this could be very useful.


---
Jan Ringoš, Tringi@mx-3.cz
http://tringi.mx-3.cz

senior programmer-analyst
n.v.t. MX-3, www.mx-3.cz




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]