# Importing constants from C headers?

**URL:** <https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251>\
**Category:** Google Group\
**Created:** [September 1, 2014, 2:49am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251 "2014-09-01T02:49:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)\
**Post date:** [September 1, 2014, 2:49am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/1 "2014-09-01T02:49:39Z")

</div>

Hi all,

Is there a general way to import preprocessor-defined constants from C  
headers into the statics language? $extval can’t be used there.

~Shea

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [September 1, 2014, 3:08am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/2 "2014-09-01T03:08:58Z")

</div>

I also wondered about this. I couldn’t figure out how to do it, so I just  
defined it twice (see #define N in  
[https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/libats-/bbarker/OpenMP/TEST/omp\_for.dats](https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/libats-/bbarker/OpenMP/TEST/omp_for.dats)).  
I agree this is not really satisfactory since it seems error prone.

Brandon Barker  
brandon…@gmail.comOn Sun, Aug 31, 2014 at 10:49 PM, Shea Levy [sh...@shealevy.com](mailto:sh...@shealevy.com) wrote:

> Hi all,
> 
> Is there a general way to import preprocessor-defined constants from C  
> headers into the statics language? $extval can’t be used there.
> 
> ~Shea
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net)  
> .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 1, 2014, 3:22am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/3 "2014-09-01T03:22:02Z")

</div>

Not sure what you want exactly.

I did something like this a while ago:

[https://sourceforge.net/p/ats-lang/code/HEAD/tree/trunk/contrib/glib/HATS/glibconfig\_hats](https://sourceforge.net/p/ats-lang/code/HEAD/tree/trunk/contrib/glib/HATS/glibconfig_hats)

Then I used ‘gcc -E’ to preprocess glibconfig\_hats to generate a HATS file  
glibconfig.hats, which  
can be included in ATS code directly.On Sun, Aug 31, 2014 at 10:49 PM, Shea Levy [sh...@shealevy.com](mailto:sh...@shealevy.com) wrote:

> Hi all,
> 
> Is there a general way to import preprocessor-defined constants from C  
> headers into the statics language? $extval can’t be used there.
> 
> ~Shea
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net)  
> .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 1, 2014, 3:49am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/4 "2014-09-01T03:49:15Z")

</div>

The opposite direction is easier.

Say you store the following line in a file mydefine.hats

#define N 100

Then just put the following lines at the beginning of your code:

%{^  
#include “define.hats”  
%}  
#include “define.hats”

It shouldn’t be too bad …On Sunday, August 31, 2014 11:09:18 PM UTC-4, Brandon Barker wrote:

> I also wondered about this. I couldn’t figure out how to do it, so I just  
> defined it twice (see #define N in  
> [https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/libats-/bbarker/OpenMP/TEST/omp\_for.dats](https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/libats-/bbarker/OpenMP/TEST/omp_for.dats)).  
> I agree this is not really satisfactory since it seems error prone.
> 
> Brandon Barker  
> [brand...@gmail.com](mailto:brand...@gmail.com) \<javascript:\>
> 
> On Sun, Aug 31, 2014 at 10:49 PM, Shea Levy \<[sh...@shealevy.com](mailto:sh...@shealevy.com) \<javascript:\>\> wrote:
> 
> > Hi all,
> > 
> > Is there a general way to import preprocessor-defined constants from C  
> > headers into the statics language? $extval can’t be used there.
> > 
> > ~Shea
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > \<javascript:\>.  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net)  
> > .

---

<div class="post-metadata">

**Author:** ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)\
**Post date:** [September 1, 2014, 3:27am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/5 "2014-09-01T03:27:24Z")

</div>

Ah, that’s a clever approach. I’ll try something like that, thanks!On Sun, Aug 31, 2014 at 11:22:02PM -0400, Hongwei Xi wrote:

> Not sure what you want exactly.
> 
> I did something like this a while ago:
> 
> [The ATS PL System / Code / [r3515] /trunk/contrib/glib/HATS/glibconfig\_hats](https://sourceforge.net/p/ats-lang/code/HEAD/tree/trunk/contrib/glib/HATS/glibconfig_hats)
> 
> Then I used ‘gcc -E’ to preprocess glibconfig\_hats to generate a HATS file  
> glibconfig.hats, which  
> can be included in ATS code directly.
> 
> On Sun, Aug 31, 2014 at 10:49 PM, Shea Levy [sh...@shealevy.com](mailto:sh...@shealevy.com) wrote:
> 
> > Hi all,
> > 
> > Is there a general way to import preprocessor-defined constants from C  
> > headers into the statics language? $extval can’t be used there.
> > 
> > ~Shea
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140901024939.GC2219%40nixos.hsd1.nh.comcast.net)  
> > .
> 
> –  
> You received this message because you are subscribed to the Google Groups “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLomq6heBJ10ftgXVGLY8sgTF8vzMdPET4KysfTmjtGSwg%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLomq6heBJ10ftgXVGLY8sgTF8vzMdPET4KysfTmjtGSwg%40mail.gmail.com).

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [September 1, 2014, 4:05am UTC](https://discourse.ats-lang.org/t/importing-constants-from-c-headers/251/6 "2014-09-01T04:05:12Z")

</div>

That would do it; somehow it never crossed my mind to #include a .hats file.

Brandon Barker  
brandon…@gmail.comOn Sun, Aug 31, 2014 at 11:49 PM, gmhwxi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> The opposite direction is easier.
> 
> Say you store the following line in a file mydefine.hats
> 
> #define N 100
> 
> Then just put the following lines at the beginning of your code:
> 
> %{^  
> #include “define.hats”  
> %}  
> #include “define.hats”
> 
> It shouldn’t be too bad …
> 
> On Sunday, August 31, 2014 11:09:18 PM UTC-4, Brandon Barker wrote:
> 
> > I also wondered about this. I couldn’t figure out how to do it, so I just  
> > defined it twice (see #define N in [githwxi (Hongwei Xi) · GitHub](https://github.com/githwxi/)  
> > ATS-Postiats-contrib/blob/master/contrib/libats-/  
> > bbarker/OpenMP/TEST/omp\_for.dats). I agree this is not really  
> > satisfactory since it seems error prone.
> > 
> > Brandon Barker  
> > [brand...@gmail.com](mailto:brand...@gmail.com)
> > 
> > On Sun, Aug 31, 2014 at 10:49 PM, Shea Levy [sh...@shealevy.com](mailto:sh...@shealevy.com) wrote:
> > 
> > > Hi all,
> > > 
> > > Is there a general way to import preprocessor-defined constants from C  
> > > headers into the statics language? $extval can’t be used there.
> > > 
> > > ~Shea
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google  
> > > Groups “ats-lang-users” group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).
> > > 
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/ats-lang-users/20140901024939.GC2219%[40nixos.hsd1.nh.comcast.net](http://40nixos.hsd1.nh.comcast.net).
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/f0158d51-eb28-4e59-9251-bb4c8a0ca565%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/f0158d51-eb28-4e59-9251-bb4c8a0ca565%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/f0158d51-eb28-4e59-9251-bb4c8a0ca565%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/f0158d51-eb28-4e59-9251-bb4c8a0ca565%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
