stringify MAKE_SQLSTATE() - Mailing list pgsql-hackers

From Teodor Sigaev
Subject stringify MAKE_SQLSTATE()
Date
Msg-id [email protected]
Whole thread Raw
Responses Re: stringify MAKE_SQLSTATE()
List pgsql-hackers
Hi!

Following discussion at https://commitfest.postgresql.org/5/190/ patch, I found 
(at seems to me) a way to stringify MAKE_SQLSTATE(), the idea is to use char 
array as string:

#include <stdio.h>

#define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) \
((char[]){(char)(ch1),(char)(ch2),(char)(ch3),(char)(ch4),(char)(ch5),(char)'\0'})

#define ERRCODE_WARNING_DEPRECATED_FEATURE MAKE_SQLSTATE('0','1','P','0','1')

int
main(int argn, char* argv[])
{    char    *x = ERRCODE_WARNING_DEPRECATED_FEATURE;
    printf("%s\n", x);
    return 0;
}

That works for clang ang gcc48 with flags -Wall -Wextra -ansi (or -std=c90) 
without warnings, but doesn't work with -pedantic. Is that enough to to work 
with other compilers?

-- 
Teodor Sigaev                                   E-mail: [email protected]
  WWW: http://www.sigaev.ru/
 



pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: [PROPOSAL] VACUUM Progress Checker.
Next
From: Robert Haas
Date:
Subject: Re: optimizing vacuum truncation scans