Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:34:22+00:00 2026-06-09T12:34:22+00:00

I am writing some code to get a hex dump of the stack in

  • 0

I am writing some code to get a hex dump of the stack in c. I keep getting a compile error on this following line when I compile it using gcc in ubuntu however it compiles fine under gcc in windows.

char buffer[10];
for (int i=0;i<20;i++)
    printf("0x%lx => 0x%lx\n", &(buffer[i]), ((long *)buffer)[i]);

This is the message the compiler gives.

warning: format ‘%lx’ expects type ‘long unsigned int’, but argument 2 has type ‘char *’

Can someone please tell me if I am doing someting wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:34:23+00:00Added an answer on June 9, 2026 at 12:34 pm

    Try:

    char buffer[10];
    for (int i=0;i<20;i++)
        printf("%p => 0x%lx\n", (void*)&(buffer[i]), ((long *)buffer)[i]);
    

    The 2nd arg, &(buffer[i]) is of type char*, so it needs a cast and a %p.

    The 3rd arg, ((long *)buffer)[i], is of type long, so it needs a %lx.


    Aside: Please realize that if buffer is not long-aligned, you might get the right answer, the wrong answer, or a core dump, all depending upon your CPU, OS, OS settings, and/or compiler.

    If it were me, I’d try:

    long l;
    for(int i = 0; i < 20; i++)
        printf("%p => 0x%lx\n", (void*)(&l+i), *(&l+i));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some code in which i need to get a line from
Im running into this error that I can't work out Im writing some code
I'm writing some code that will get executed before the DOM loads, basically, using
I am writing some code and I am getting a strange error: my for
I am writing some code to type strings using the Robot class. Everything is
I'm writing some code and I need to get the window handle of the
I am writing some C code which is expected to compile on multiple compilers
While writing some code i came across this issue: #include <iostream> class random {
I am using python with scipy for writing some code to converge Cartesian coordinates
I'm writing some lines of code to get acquainted with the basics of Quartz

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.