Richard23
Richard23

Reputation: 139

Datatype question

I am trying to port a C program to a SPARC architecture that has the following type declaration

#include <stdint.h>

typedef uint32_t  WORD ;
typedef uint64_t DWORD ; 

The trouble is, that the compiler tells me that stdint.h cant be found. Hence, I redefined those datatypes as follows:

unsigned int  WORD; 
unsigned long DWORD;

This seems for me the straightforward declaration, but the program is not expecting as it should. Did I maybe miss something?

Thanks

Upvotes: 1

Views: 144

Answers (3)

nos
nos

Reputation: 229058

So, you need an integer that's 32 bit and another that's 64 bit.

It might be that int and longs are the same on your architecture, and if your compiler supports long long, that might be 64 bit while int might be 32 bit. Check your compiler docs for what it supports, and if it has any extension (e.g. some compilers might provide an __int64 type). This could be what you need:

  typedef unsigned int  WORD; 
  typedef unsigned long long DWORD;

Anyway, I'd write a small program to verify the sizes of integers on your host, so you can pick the correct one , that is printf the sizeof(int), sizeof(long) and so on. (On a sparc host CHAR_BIT will be 8, so it's all atleast a multple of 8 bits. )

Also, since you're porting to a sparc host, make sure your code is not messing up somewhere regarding endianess

Upvotes: 0

Paul R
Paul R

Reputation: 212929

If your compiler/OS does not have <stdint.h> then the best thing to do is implement your own version of this header rather than not modify the code you're trying to port. You probably only need a subset of the types that are normally defined in <stdint.h>, e.g.

//
// stdint.h
//

typedef int int32_t; // signed 32 bit int
typedef unsigned long long uint64_t; // unsigned 64 bit int

(obviously you need to know the sizes of the various integer types on your particular platform to do this correctly).

Upvotes: 0

CB Bailey
CB Bailey

Reputation: 791391

<stdint.h> and the types uint32_t and uint64_t are "new" in ISO/IEC 9899:1999. Your compiler may only conform to the previous version of the standard.

If you are sure that unsigned int and unsigned long are 32-bit and 64-bit respectively then you shouldn't have any problems (at least not ones due to the typedefs themselves). As you are, this may not be the case. Do you know (or can you find out) if your compiler supports unsigned long long?

I'm guessing that unsigned int is probably 32-bit, how old is your SPARC?

Upvotes: 1

Related Questions