[질문] std::list의 size()관련 (64비트)

bizzare의 이미지

다음과 같은 코드를 빌드해봤습니다.
32비트로 빌드할 때는 아무 문제없이 잘 되는데,
64비트로 빌드할 때는 int iSize = a.size(); 에서 warning이 나는군요.

warning : conversion from 'size_t' to 'int', possible loss of data

결국 std::list의 size()가 size_t 타입으로 리턴한다는 이야기인데,
그동안 수없이 int 또는 UINT로 이 값을 받아서 쓰고 있었거든요.
size()를 모조리 고치는 건 좋은 방법이 아닐 것 같아서 이 부분을 어떻게 해결하면 좋을 지
조언을 얻고 싶습니다.

#include

int main(int argc, char* argv[])
{
std::list a, b;
a.push_back(10);
a.push_back(11);

b.push_back(222);

int iSize = a.size();
return 0;
}

superwtk의 이미지

site_t iSize = a.size(); :mrgreen:

doldori의 이미지

Quote:
size()를 모조리 고치는 건 좋은 방법이 아닐 것 같아서 이 부분을 어떻게 해결하면 좋을 지
조언을 얻고 싶습니다.

모조리 고치는 것이 좋은 방법입니다. :-)
그리고 많은 구현체에서 list::size_type과 size_t가 같을 테지만,
그래도 역시 list::size_type을 쓰는 것이 좋습니다.
ssehoony의 이미지

32비트에서도 a.size() 를 int 는 받는건 경고가 떳을텐데요.

위 경고는 1차적으로 32비트/64비트 문제가 아니고
컴파일러의 버전이 올라가서 기존 버전에 없던 signedness 체크 기능 때문에 생기는 경고문구입니다.
사실상 프로그램 작동에는 거의 문제가 없을 겁니다.
stl 의 사이즈가 20억을 넘기지 않을테니깐요.

경고문구도 나오지 않는 소스코드를 만드시는게 목적이시라면
모든 부분에서 size_type 를 사용하시는 방법이 최선이고
아니라면 그냥 경고 무시하고 사용하세요.
추후에 소수를 꼭 수정해야 할 때 그때 그때 조금씩 작업하시구요.
signedness 체크 경고 문구가 보기 싫으시면 구버전 컴파일러를
사용하시던지 옵션에서 signedness 체크 부분을 제거하도록 하셔도 되겠네요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.