stringify MAKE_SQLSTATE()

From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Subject: stringify MAKE_SQLSTATE()
Date: 2015-07-22 13:52:52
Message-ID: 55AFA034.6040601@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-07-22 13:59:22 Re: stringify MAKE_SQLSTATE()
Previous Message Simon Riggs 2015-07-22 12:24:21 Re: [PROPOSAL] VACUUM Progress Checker.