Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Ke Du <duke@naive.systems>
To: linux-sparse@vger.kernel.org
Cc: Xiao Jia <xjia@naive.systems>
Subject: check idea: include sparse as a library in C++
Date: Tue, 22 Jun 2021 02:45:41 -0400	[thread overview]
Message-ID: <88596afa-76f2-8c2f-d80e-572d1e57369e@naive.systems> (raw)

Hi,

I want to include sparse as a library in C++ and access fields of the 
structs such as symbol and expression directly, but some of the 
variables in sparse are keywords in C++ so they cannot be included in 
C++ directly. I have several fixes below that are not ideal, and any 
feedback is appreciated.

1. Append an underscore to C++ keywords, for instance change new to 
new_. The change only involves the code that I included so there might 
be some C++ keywords in sparse that are unchanged.

2. Replace every keyword with a macro:

     #ifdef __cplusplus
     #define NEW new_
     #else
     #define NEW new
     #endif

Similar to solution 1, this is not complete, and both 1 and 2 involves 
about 200 changes already.

3. When including sparse header files, guard them with

     #define new new_
     #include ...
     #define new_ new

This does not involve change to sparse but it imposes weird restriction 
to the ordering of other C++ libraries that I do not understand at all.

I can send the patches if one of the fixes is acceptable. Alternatively, 
if there is a better way, please let me know.

Cheers,
-- Ke

             reply	other threads:[~2021-06-22  6:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22  6:45 Ke Du [this message]
2021-07-26 18:28 ` check idea: include sparse as a library in C++ Luc Van Oostenryck
2021-08-13  1:25   ` [PATCH 0/2] fixes for using sparse as a C++ library Ke Du
2021-08-13  1:25     ` [PATCH 1/2] expose more functions to C++ in header files Ke Du
2021-11-17  9:44       ` Xiao Jia
2021-08-13  1:25     ` [PATCH 2/2] make implicit type conversion explicit Ke Du

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88596afa-76f2-8c2f-d80e-572d1e57369e@naive.systems \
    --to=duke@naive.systems \
    --cc=linux-sparse@vger.kernel.org \
    --cc=xjia@naive.systems \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).