Author Topic: print variable address  (Read 4776 times)

Offline Mich

  • Single posting newcomer
  • *
  • Posts: 4
print variable address
« on: August 05, 2014, 02:43:10 pm »
Hello,
I would like to display the memory address of an array. I have this small C code:
Quote
unsigned char NameTab[] = "D:\\data\\util2\\myTest.DAT";
printf("addr NameTab %X\r\n", NameTab);
I have this warning at compilation:
warning: format '%X' expects argument of type 'unsigned int', but argument 2 has type 'unsigned char *' [-Wformat=]

Do you have any suggestion to display the memory address of a variable by a printf?

Best regards

ToApolytoXaos

  • Guest
Re: print variable address
« Reply #1 on: August 05, 2014, 04:03:19 pm »
Mich, this has nothing to do with Code::Blocks, but rather how to use C programming language. I'm sure there are many books, let alone websites that show you a few ways to get an address of a variable.

Offline Mich

  • Single posting newcomer
  • *
  • Posts: 4
Re: print variable address
« Reply #2 on: August 05, 2014, 04:20:16 pm »
I have this warning only with codeblocks ....

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: print variable address
« Reply #3 on: August 05, 2014, 04:40:42 pm »
I have this warning only with codeblocks ....
http://wiki.codeblocks.org/index.php?title=FAQ-General#Q:_What_Code::Blocks_is_not.3F

And please (re-?)read the rules of this website:
[...]
2. Compiler/Linker errors are NOT Code::Blocks errors. Usually, C++ newcomers tend to confuse the Editor/IDE (Code::Blocks) with the Compiler (MINGW / GCC). You may see some errors in the compiler output because you missed to do something right in your code. But that's not Code::Blocks troubleshooting, that's C++ troubleshooting and does not belong in here. If your program doesn't compile, READ THE C++ MANUAL.
[...]
Finale note: Ignoring these rules may result in the topic being (silently) locked and/or even removed completely without any notice.
[...]
You accepted to follow these rules when registering here, so please do it !

Offline Mich

  • Single posting newcomer
  • *
  • Posts: 4
Re: print variable address
« Reply #4 on: August 06, 2014, 02:12:35 pm »
Ok
I guess that I am not the first people to confuse so may be you know the compiler forum url. If yes, could you indicate it please?
Best regards
Michel

ToApolytoXaos

  • Guest
Re: print variable address
« Reply #5 on: August 06, 2014, 02:54:02 pm »
Google is your friend for generic information, let alone about finding for you how printf() works.

http://man7.org/linux/man-pages/man3/printf.3.html

Offline Mich

  • Single posting newcomer
  • *
  • Posts: 4
Re: print variable address
« Reply #6 on: August 06, 2014, 03:29:26 pm »
My issue is not around printf by around mktime(). I do not anderstand why mktime() change the .tm_isdst during the 26oct-27oct night. If you ntry this code you will find that the difference is 25H instead of 24H. If I force the .tm_isdst to 0 before mktime() call, a reverse ctime() call does gives the correct answer for "winter" date...

Quote
        struct tm tmbidon;
        time_t tbidon, myreference, tdiff;

        tmbidon.tm_isdst = -1;
        tmbidon.tm_year = 13 + 100;   // ref 1900
        tmbidon.tm_mon = 9; /* Months *since* january: 0-11 */
        tmbidon.tm_mday = 27;
        tmbidon.tm_hour = 9;
        tmbidon.tm_min = 40;
        tmbidon.tm_sec = 0;
        myreference = mktime(&tmbidon);

        tmbidon.tm_isdst = -1;
        tmbidon.tm_mday = 26;
        tbidon = mktime(&tmbidon);
        tdiff = myreference-tbidon;
        printf("diff %I64usec  %fH\n", (u64)tdiff, ((float)tdiff)/3600);
        printf("myreference %s", ctime(&myreference));
        printf("tbidon %s", ctime(&tbidon));


        tmbidon.tm_isdst = 0;
        tmbidon.tm_year = 13 + 100;   // ref 1900
        tmbidon.tm_mon = 9; /* Months *since* january: 0-11 */
        tmbidon.tm_mday = 27;
        tmbidon.tm_hour = 9;
        tmbidon.tm_min = 40;
        tmbidon.tm_sec = 0;
        myreference = mktime(&tmbidon);

        tmbidon.tm_isdst = 0;
        tmbidon.tm_mday = 26;
        tbidon = mktime(&tmbidon);
        tdiff = myreference-tbidon;
        printf("diff %I64usec  %fH\n", (u64)tdiff, ((float)tdiff)/3600);
        printf("myreference %s", ctime(&myreference));
        printf("tbidon %s", ctime(&tbidon));

Result:
diff 90000sec  25.000000H                     <= ???
myreference Sun Oct 27 09:40:00 2013
tbidon Sat Oct 26 09:40:00 2013
diff 86400sec  24.000000H
myreference Sun Oct 27 09:40:00 2013
tbidon Sat Oct 26 10:40:00 2013             <= ???

I agree that this not the appropriated forum and I will look for the coorect one.



ToApolytoXaos

  • Guest
Re: print variable address
« Reply #7 on: August 06, 2014, 03:43:03 pm »
Mich, please respect the rules of this forum.

This is NOT a programming forum that teach people how to program, but rather to report possible bugs you might have detected in Code::Blocks, or suggest improvements on existing parts of IDE.

I'm sure you can use Google to find why mktime() is not working.