Sponsored Content
Top Forums Programming "char" memory layout problem! Post 302687755 by micky.zhou on Friday 17th of August 2012 03:51:49 AM
Old 08-17-2012
"char" memory layout problem!

In the following code, why the final result of "usC=cA+(char)ucB;" is 0xFF00?
In my opioion the memory layout of cA is "10000000" and
(char)cB is "10000000",usC type is unsigned short ,so the result should be "100000000" ,the 0x100.
Please help tell me what is wrong? Thanks!!Smilie

Code:
#include<stdio.h>

int main(int argc,char *argv[])
{

    char cA;
    unsigned char ucB;
    unsigned short usC;
    cA = 128;    
    ucB = 128;

    usC = cA+ucB;
    printf("0x%x\n",usC);

    usC=cA+(short)ucB;
    printf("0x%x\n",usC);

    usC = (unsigned char)cA+ucB;
    printf("0x%x\n",usC);

    usC=cA+(char)ucB;
    printf("0x%x\n",usC);


    return 0;

}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. UNIX and Linux Applications

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or question of my own) is: Oracle tns listener, "CT_LISTENER", and the enterprise manager (EM) of the instance, which is uniq instance and called... (0 Replies)
Discussion started by: talipk
0 Replies

3. UNIX for Advanced & Expert Users

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses... Here is the configuration of my system: * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or... (1 Reply)
Discussion started by: talipk
1 Replies

4. Solaris

significance of "+" char in SunOS "ls -l" output

Hi, I've noticed that the permissions output from "ls -l" under SunOS differs from Linux in that after the "rwxrwxrwx" field, there is an additional "+" character that may or may not be there. What is the significance of this character? Thanks, Suan (6 Replies)
Discussion started by: sayeo
6 Replies

5. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

problem with char "%"

hi all i have a problem...when i do the command my output is "n%" where n is a number but i want to delete the charater "%" . how i can delete it Thanks a lot REgards (2 Replies)
Discussion started by: FrancescoIt
2 Replies

8. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies

9. Shell Programming and Scripting

Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work. I'm not very good at scripting, so bear with me please. Working on Linux RHEL I've been able to filter and edit and clean up using sed, but I have a problem with moving lines. ... (9 Replies)
Discussion started by: rex007can
9 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
caca_conio_text_info(3caca)					      libcaca					       caca_conio_text_info(3caca)

NAME
caca_conio_text_info - DOS text area information. SYNOPSIS
Data Fields unsigned char winleft unsigned char wintop unsigned char winright unsigned char winbottom unsigned char attribute unsigned char normattr unsigned char currmode unsigned char screenheight unsigned char screenwidth unsigned char curx unsigned char cury Detailed Description This structure stores text area information for the DOS conio.h compatibility layer. Field Documentation unsigned char caca_conio_text_info::winleft left window coordinate unsigned char caca_conio_text_info::wintop top window coordinate unsigned char caca_conio_text_info::winright right window coordinate unsigned char caca_conio_text_info::winbottom bottom window coordinate unsigned char caca_conio_text_info::attribute text attribute unsigned char caca_conio_text_info::normattr normal attribute unsigned char caca_conio_text_info::currmode current video mode: BW40, BW80, C40, C80, or C4350 unsigned char caca_conio_text_info::screenheight text screen's height unsigned char caca_conio_text_info::screenwidth text screen's width unsigned char caca_conio_text_info::curx x-coordinate in current window unsigned char caca_conio_text_info::cury y-coordinate in current window Author Generated automatically by Doxygen for libcaca from the source code. Version 0.99.beta18 Fri Apr 6 2012 caca_conio_text_info(3caca)
All times are GMT -4. The time now is 09:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy