Open v0dro opened 8 years ago
You're mistaken. It namespaces them in C++, and in C it adds the nm_ prefix:
No what I'm saying is that the contents of the enum should be prefixed too. So it should be NM_FLOAT64
not FLOAT64
.
A quick program after compiling with gcc's -E
option yields this output:
Program:
#include <stdio.h>
#define NM_DEF_ENUM(name, ...) \
typedef enum nm_ ## name { \
__VA_ARGS__ \
} nm_ ## name;
NM_DEF_ENUM(dtype_t, BYTE = 0, // unsigned char
INT8 = 1, // char
INT16 = 2, // short
INT32 = 3, // int
INT64 = 4, // long
FLOAT32 = 5, // float
FLOAT64 = 6, // double
COMPLEX64 = 7, // Complex64 class
COMPLEX128 = 8, // Complex128 class
RUBYOBJ = 9); // Ruby VALUE type
int main()
{
nm_dtype_t e;
e = BYTE;
printf("BYTE : %d\n", e);
return 0;
}
Output:
typedef enum nm_dtype_t { BYTE = 0, INT8 = 1, INT16 = 2, INT32 = 3, INT64 = 4, FLOAT32 = 5, FLOAT64 = 6, COMPLEX64 = 7, COMPLEX128 = 8, RUBYOBJ = 9 } nm_dtype_t;
;
int main()
{
nm_dtype_t e;
e = BYTE;
printf("BYTE : %d\n", e);
return 0;
}
Having NM_
everywhere would avoid clashes with other libraries who might use data type names similar to ours.
Why? It's in a namespace?
Not sure what you mean. What's in a namespace?
The terms that are inside the enumerator (like BYTE
and INT32
) are not namespaced.
Yes they are. It's a macro which puts them in a namespace for c++ or gives them prefixes for C. On Sat, Feb 20, 2016 at 12:06 AM Sameer Deshmukh notifications@github.com wrote:
Not sure what you mean. What's in a namespace?
The terms that are inside the enumerator (like BYTE and INT32) are not namespaced.
— Reply to this email directly or view it on GitHub https://github.com/SciRuby/nmatrix/issues/468#issuecomment-186519213.
In my program I was able to access them as BYTE
or FLOAT64
(see main()
function above).
Oh, hmm. You may actually be right, and I'm not sure how that happened if so. Sorry. ^^;;
Just to check, can you figure out how to generate the post-processed sources using gcc and confirm this? You're looking for a .i file, I think.
You mean for the whole gem? Won't that be complex to sift through? Copy pasting the macros from nmatrix.h
into another file and compiling with -E
would be easier if I'm getting at what you're getting at.
Uh, no. Just add the gcc flag for outputting preprocessed files to extconf, and go look in the build directory.
Currently the enum defining stype and dtype for an nmatrix does not namespace it's values.
Prefixing every value with
NM_
would suffice. @mohawkjohn thoughts?