1

In Java Byte wrapper classes is there like

byte-Byte
int-Integer
float-Float etc

i want to use wrapper classes in c so anyone let me know how to use wrapper classes in c and how to write this in c??

JAVA:

Byte arr= 0x03;
6
  • 3
    in C there is no classes at all... Commented Aug 2, 2012 at 12:31
  • Perhaps you'd just tell us what functionality you want? Commented Aug 2, 2012 at 12:32
  • @FelicePollano Are you saying C has no class? How terribly rude :-) Commented Aug 2, 2012 at 12:32
  • 1
    You can't really, as C doesn't have any support to create new types like in Java or C++. Commented Aug 2, 2012 at 12:33
  • 1
    It has support to create new types, just not new classes. C structs are basically just a dumb collection of data. Commented Aug 2, 2012 at 12:36

2 Answers 2

2

In C there are no classes at all. You could create a struct with a char member but I'm not really sure why you'd want to do that.

In C++, you could create a wrapper class. You just need to define implicit conversions to and from char to simulate autoboxing, as well as whatever methods you think the wrapper class should have.

Also, the equivalent of the Java 'byte' type in C and C++ is signed char.

Sign up to request clarification or add additional context in comments.

2 Comments

That's just because everything is signed in Java.
@Bo, actually, chars are unsigned.
1

In C you write char arr = 0x03;. There are no "wrapppers" or "boxing" for POD types. And you don't really need them.

4 Comments

for this code byte[] arr1=new byte[]{0x01}; i have written char arr1[]={0x01}; so for Byte there's no wrapper class in c so i can write like this char arr = 0x03; which is equivalent to Byte arr= 0x03; right?? thank you
@poppy: Yes, you can. That is, if you have a single byte. If you write byte [] arr1... in Java, that is called an array, and in C it could be either char *array or char array[].
then In C what's the equivalent for java Integer,Short,Float wrapper class??
@poppy: See "Simple Java Data" here — d.umn.edu/~gshute/java/c2java.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.