Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
August 18, 2018, 09:26:56 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: 10.7  (Read 3049 times)
sir
Full Member
***
Posts: 118


Email
« on: March 18, 2009, 07:53:23 PM »

/*
Write a program to ascertain whether sign extension is performed
on signed char variables on your machine.
*/
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   
    char charTest = -25;
    int intTest = charTest;
   
    NSLog(@"The char is %c and the int value is %i", charTest, intTest);
   
    [pool drain];
    return 0;
}
Logged
onwin
Newbie
*
Posts: 5


« Reply #1 on: July 04, 2009, 12:02:24 PM »

What is a signed char? I thought that char is any non-numeric variable.
Logged
TheWildJacko
Newbie
*
Posts: 2


« Reply #2 on: September 04, 2009, 04:59:05 PM »

Code: (Objective-C)
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

BOOL signExtension;
char c = '\377';

if ((int) c > -(int) c)
signExtension = NO;
else
signExtension = YES;

NSLog(@"Machine performs sign extension?  %@", (signExtension ? @"YES" : @"NO"));

    [pool drain];
    return 0;
}
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.