• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Getting C compiler to recognize OS

AlexWade

Member
Here is my problem:

I'm writting a class to convert to strings and numbers and vice-versa Java style. I'm doing this because I really like the way Java handles data conversions (i.e. INT.parseInt(...)).

The problem is, I cannot find any numbers to strings functions in the ANSI library. So, instead of taking to task writing these myself, I found some OS specific functions.

Solaris UNIX, for instance, has lltostr. Visual Studio .NET has _ltostr. Each has different parameters. What I want is something that I can use on UNIX, Linux, Windows since I'll be using all 3 regularlly.

Now, this is how I am implimenting my method.

char* parse__::STRING(long value) {
#ifdef MICROSOFT__DOT_NET
// use _ltostr
#endif
#elif defined(UNIX_SOLARIS)
// use lltostr
#else
throw exception("Unsupported compiler");
#endif
return NULL;
}

And I want to have something
#if using Solaris #define UNIX_SOLARIS
#elif using .NET #define MICROSOFT__DOT_NET

The only directives I've found for doing this sort of thing is OS specific. That is no good. Any ideas? I have to precompiler directives for some parts because if I don't, the compiler balks about undeclared identifier. Better yet, is there an ANSI number to string like atoi or atof?

Thanks
Wade
 
Originally posted by: AlexWade
Here is my problem:
The problem is, I cannot find any numbers to strings functions in the ANSI library. So, instead of taking to task writing these myself, I found some OS specific functions.

Forget C, use C++.



 
Originally posted by: Nothinman
I believe strings are part of the C++ standard now, if you're using C you can't use classes at all.

Sure you can... if you are tricky.

 
Originally posted by: AlexWade
Here is my problem:

I'm writting a class to convert to strings and numbers and vice-versa Java style. I'm doing this because I really like the way Java handles data conversions (i.e. INT.parseInt(...)).

The problem is, I cannot find any numbers to strings functions in the ANSI library. So, instead of taking to task writing these myself, I found some OS specific functions.

Solaris UNIX, for instance, has lltostr. Visual Studio .NET has _ltostr. Each has different parameters. What I want is something that I can use on UNIX, Linux, Windows since I'll be using all 3 regularlly.

Now, this is how I am implimenting my method.

char* parse__::STRING(long value) {
#ifdef MICROSOFT__DOT_NET
// use _ltostr
#endif
#elif defined(UNIX_SOLARIS)
// use lltostr
#else
throw exception("Unsupported compiler");
#endif
return NULL;
}

And I want to have something
#if using Solaris #define UNIX_SOLARIS
#elif using .NET #define MICROSOFT__DOT_NET

The only directives I've found for doing this sort of thing is OS specific. That is no good. Any ideas? I have to precompiler directives for some parts because if I don't, the compiler balks about undeclared identifier. Better yet, is there an ANSI number to string like atoi or atof?

Thanks
Wade

Your use of the preprocesser like that hurts, it hurts bad.

 
Originally posted by: AlexWade
Here is my problem:

I'm writting a class to convert to strings and numbers and vice-versa Java style. I'm doing this because I really like the way Java handles data conversions (i.e. INT.parseInt(...)).

The problem is, I cannot find any numbers to strings functions in the ANSI library. So, instead of taking to task writing these myself, I found some OS specific functions.

Solaris UNIX, for instance, has lltostr. Visual Studio .NET has _ltostr. Each has different parameters. What I want is something that I can use on UNIX, Linux, Windows since I'll be using all 3 regularlly.

Now, this is how I am implimenting my method.

char* parse__::STRING(long value) {
#ifdef MICROSOFT__DOT_NET
// use _ltostr
#endif
#elif defined(UNIX_SOLARIS)
// use lltostr
#else
throw exception("Unsupported compiler");
#endif
return NULL;
}

And I want to have something
#if using Solaris #define UNIX_SOLARIS
#elif using .NET #define MICROSOFT__DOT_NET

The only directives I've found for doing this sort of thing is OS specific. That is no good. Any ideas? I have to precompiler directives for some parts because if I don't, the compiler balks about undeclared identifier. Better yet, is there an ANSI number to string like atoi or atof?

Thanks
Wade


Seriously though, couldn't you wrap up a CString for most of the functionality?
 
um, try atoi/atol for ints....
edit: um oops, thats the wrong direction...

or sprintf for any type....



sprintf is the function you are looking for.

If it's C++ you can send the numbers into a stringstream.
 
Originally posted by: Nothinman
Sure you can... if you are tricky.

structs with function pointers aren't classes =)

Seriously though, couldn't you wrap up a CString for most of the functionality?

Isn't CString a part of MFC or ATL which would make it only work in VS?

Yea... but I thought it was made part of the ansi standard a little while back.

There's this nice class out there on the web somewhere called CStdString. It's exactly like CString except, it'll compile on just about anything. I think... codeproject.com might have it.
 
Back
Top