LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2004, 06:34 PM   #1
dvm
Member
 
Registered: Sep 2004
Posts: 62

Rep: Reputation: 16
trying out exercises from Kernighan and Ritchie


Hi, I'm trying to do an exercise from the C programming language. It asks to create a program to find out the ranges of the data types from standard headers. I believe the header that holds these ranges is limits.h
The problem is I can't get proper results (btw I'm using slack's 10.0 default gcc)
In the header there is:
Code:
#define UCHAR_MAX 255

#ifdef __CHAR_UNSIGNED__
#define CHAR_MIN  0
#define CHAR_MAX  UCHAR_MAX
#else
#define CHAR_MIN SCHAR_MIN
#define CHAR_MIN SCHAR_MAX
#endif.
Now in my program, I'm trying to do:
Code:
#define __CHAR_UNSIGNED__
printf("uchar:\t%d\t%d\n", CHAR_MIN, UCHAR_MAX);
printf("schar:\t%d\t%d\n", SCHAR_MIN, SCHAR_MAX);
But whenever I run the program I get [-128, 255] for unsigned char and [-128, 127] for signed.
The #define __CAHR_UNSIGNED__ has no effect? What is the proper solution?
Thanks for your time
 
Old 11-22-2004, 06:54 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You have to #define __CHAR_UNSIGNED__ before doing #include <limits.h>
 
Old 11-22-2004, 07:07 PM   #3
dvm
Member
 
Registered: Sep 2004
Posts: 62

Original Poster
Rep: Reputation: 16
Thanks dude! I can't believe I made that mistake. Better learn from it
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Exercises - Where can I find them? BenChase Slackware 3 12-15-2003 07:45 AM
exercises for learning c... Sky Programming 25 07-18-2002 01:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration