HP-UX에서 type conversion 관련해서 궁금한 것이 있습니다.

nondie의 이미지

안녕하세요.

리눅스하고 솔라리스에서만 개발을 해 오다 HP-UX는 처음 프로그래밍을 하는 개발자입니다.
코딩중에 2가지 문제에 부딫혔습니다. 일단 아래와 같은 코드가 있다고 할 때,

int main(void)
{
        int     i = 1;
        char    c1, c2 = 'a';
 
        c1 += i;
        c1 += c2;
 
        return 0;
}

HP c compiler에서 워닝 레벨을 최대로 하여 컴파일을 하면 2가지 문제가 발생합니다.

$ cc +w a.c
Warning (suggestion) 818: "a.c", line 7 # Type 'int' is larger than type
    'char', truncation in value may result.
            c1 += i;
            ^^^^^^^
Warning (suggestion) 818: "a.c", line 8 # Type 'int' is larger than type
    'char', truncation in value may result.
            c1 += c2;
            ^^^^^^^^

첫번째 warning의 경우, c1 = c1 + i; 와 동일하므로 c1+i가 integer가 되니까 warning이 되는건 맞고 그래서 c1+i를 (char)(c1+i)로 type conversion을 하면 되는데 문제는 c1 += 1;의 구문의 경우, type conversion을 할 수가 없습니다. c1 += 1;의 형태에서 type conversion할 수 있는 방법이 없을까요? 불가능할 것 같긴 한데 혹시 내가 모르는 어떤 방법이 있나 해서 물어보고자 합니다.

두번째 warning의 경우는 더 이해할 수가 없는데요, linux에서 gcc의 경우에는 warning이 나오지 않습니다.
c1 += c2; <=> c1 = c1 + c2; 이니까 c1+c2의 경우는 char가 되고 그래서 c1에 값을 입력하는데 아무 문제가 없는데요, 이상하게도 HP-UX의 c compiler는 이걸 warning 처리하네요.

나름대로 오랫동안 개발을 해 왔다고 생각했지만 아직도 아는 것보다 모르는게 더 많네요. 에휴... -_-

ps. 참고로 HP-UX의 c compiler의 버전은 아래와 같습니다.
$ cc --version
cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]

bootmeta의 이미지


주제와 상관 없는 사족입니다.

mozilla c++ portable guide문서를 보면 portable code 생성에 문제가 되는 컴파일러 중 하나가 hp compiler더군요.

http://www.mozilla.org/hacking/portable-cpp.html

tj의 이미지

int 보다 작은 정수형 연산은 무조건 int로 promote된 후 계산됩니다. 그리고 그 컴파일 워닝은 그냥 무시하던지 워닝 레벨을 낮추시는 게 좋을 것 같습니다. 말도 안되는 워닝 피하려고 코드 지저분하게 할 필요는 없으니까요. 그냥 좀 모자란 컴파일러라고 생각하세요.

nondie의 이미지

가급적 워닝 레벨을 최대로 유지하려고 하거든요.
원래 개발 스타일이 그렇고 실제로 지금 HP-UX에서 개발중인 코드에서도 워닝을 그대로 두고 실행시키면 문제가 생기는 부분이 많이 있어서요.
근데 확실히 HP compiler는 좀 특이한 것 같네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.