diff mbox series

[7/7] teach sparse about C17

Message ID 20191128204225.7002-8-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series add support for '-std=c17' | expand

Commit Message

Luc Van Oostenryck Nov. 28, 2019, 8:42 p.m. UTC
No real support is done here (or is needed) but the __STDC_VERSION__
will return the correct value.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c | 13 +++++++++++++
 lib.h |  2 ++
 2 files changed, 15 insertions(+)

Comments

Ramsay Jones Dec. 1, 2019, 4:25 p.m. UTC | #1
On 28/11/2019 20:42, Luc Van Oostenryck wrote:
> No real support is done here (or is needed) but the __STDC_VERSION__
> will return the correct value.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  lib.c | 13 +++++++++++++
>  lib.h |  2 ++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/lib.c b/lib.c
> index 7f7ca846b..8fddae450 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -1079,6 +1079,15 @@ static char **handle_switch_s(const char *arg, char **next)
>  		else if (!strcmp(arg, "gnu11"))
>  			standard = STANDARD_GNU11;
>  
> +		else if (!strcmp(arg, "c17") ||
> +			 !strcmp(arg, "c18") ||
> +			 !strcmp(arg, "iso9899:2017") ||
> +			 !strcmp(arg, "iso9899:2018"))
> +			standard = STANDARD_C17;
> +		else if (!strcmp(arg, "gnu17") ||
> +			 !strcmp(arg, "gnu18"))
> +			standard = STANDARD_GNU17;
> +

Yes, I knew about C17, but out of nowhere I started hearing
about C18! ;-) As far as I can tell, this is just C17, but
because it crept into 2018 before final approval, come people
are starting to call it C18. However, the __STDC_VERSION__
value is still 201710L, right?

ATB,
Ramsay Jones

>  		else
>  			die ("Unsupported C dialect");
>  	}
> @@ -1421,6 +1430,10 @@ static void predefined_macros(void)
>  	case STANDARD_GNU11:
>  		predefine("__STDC_VERSION__", 1, "201112L");
>  		break;
> +	case STANDARD_C17:
> +	case STANDARD_GNU17:
> +		predefine("__STDC_VERSION__", 1, "201710L");
> +		break;
>  	}
>  	if (!(standard & STANDARD_GNU) & (standard != STANDARD_NONE))
>  		predefine("__STRICT_ANSI__", 1, "1");
> diff --git a/lib.h b/lib.h
> index 7958359c1..3e565c6fd 100644
> --- a/lib.h
> +++ b/lib.h
> @@ -235,6 +235,8 @@ enum standard {
>  	STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU,
>  	STANDARD_C11,
>  	STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU,
> +	STANDARD_C17,
> +	STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU,
>  };
>  extern enum standard standard;
>  
>
Luc Van Oostenryck Dec. 1, 2019, 8:20 p.m. UTC | #2
On Sun, Dec 01, 2019 at 04:25:30PM +0000, Ramsay Jones wrote:
> On 28/11/2019 20:42, Luc Van Oostenryck wrote:
> > No real support is done here (or is needed) but the __STDC_VERSION__
> > will return the correct value.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > ---
> >  lib.c | 13 +++++++++++++
> >  lib.h |  2 ++
> >  2 files changed, 15 insertions(+)
> > 
> > diff --git a/lib.c b/lib.c
> > index 7f7ca846b..8fddae450 100644
> > --- a/lib.c
> > +++ b/lib.c
> > @@ -1079,6 +1079,15 @@ static char **handle_switch_s(const char *arg, char **next)
> >  		else if (!strcmp(arg, "gnu11"))
> >  			standard = STANDARD_GNU11;
> >  
> > +		else if (!strcmp(arg, "c17") ||
> > +			 !strcmp(arg, "c18") ||
> > +			 !strcmp(arg, "iso9899:2017") ||
> > +			 !strcmp(arg, "iso9899:2018"))
> > +			standard = STANDARD_C17;
> > +		else if (!strcmp(arg, "gnu17") ||
> > +			 !strcmp(arg, "gnu18"))
> > +			standard = STANDARD_GNU17;
> > +
> 
> Yes, I knew about C17, but out of nowhere I started hearing
> about C18! ;-) As far as I can tell, this is just C17, but
> because it crept into 2018 before final approval, come people
> are starting to call it C18. However, the __STDC_VERSION__
> value is still 201710L, right?

Yes, exactly. It's essentially a 'bug-fix' only version, so
nothing new and nothing controversial and so there is very few
reasons to talk about it. I think that the final approval vote
was still in 2017 but it was only published months later, in 2018. 
I think it's better known as C18 but I tend to call it C17 because
of the __STDC_VERSION__.

Best regards,
-- Luc
diff mbox series

Patch

diff --git a/lib.c b/lib.c
index 7f7ca846b..8fddae450 100644
--- a/lib.c
+++ b/lib.c
@@ -1079,6 +1079,15 @@  static char **handle_switch_s(const char *arg, char **next)
 		else if (!strcmp(arg, "gnu11"))
 			standard = STANDARD_GNU11;
 
+		else if (!strcmp(arg, "c17") ||
+			 !strcmp(arg, "c18") ||
+			 !strcmp(arg, "iso9899:2017") ||
+			 !strcmp(arg, "iso9899:2018"))
+			standard = STANDARD_C17;
+		else if (!strcmp(arg, "gnu17") ||
+			 !strcmp(arg, "gnu18"))
+			standard = STANDARD_GNU17;
+
 		else
 			die ("Unsupported C dialect");
 	}
@@ -1421,6 +1430,10 @@  static void predefined_macros(void)
 	case STANDARD_GNU11:
 		predefine("__STDC_VERSION__", 1, "201112L");
 		break;
+	case STANDARD_C17:
+	case STANDARD_GNU17:
+		predefine("__STDC_VERSION__", 1, "201710L");
+		break;
 	}
 	if (!(standard & STANDARD_GNU) & (standard != STANDARD_NONE))
 		predefine("__STRICT_ANSI__", 1, "1");
diff --git a/lib.h b/lib.h
index 7958359c1..3e565c6fd 100644
--- a/lib.h
+++ b/lib.h
@@ -235,6 +235,8 @@  enum standard {
 	STANDARD_GNU99 = STANDARD_C99 | STANDARD_GNU,
 	STANDARD_C11,
 	STANDARD_GNU11 = STANDARD_C11 | STANDARD_GNU,
+	STANDARD_C17,
+	STANDARD_GNU17 = STANDARD_C17 | STANDARD_GNU,
 };
 extern enum standard standard;