DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Floyd's Cycle Algorithm for Fraud Detection in Java Systems
  • Sliding Window
  • Tarantool: Speeding Up Development With Rust
  • How to Implement Linked Lists in Go

Trending

  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Comparing SaaS vs. PaaS for Kafka and Flink Data Streaming
  • Scalability 101: How to Build, Measure, and Improve It
  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  1. DZone
  2. Data Engineering
  3. Data
  4. Eclipse Debugging With Pointers and Arrays

Eclipse Debugging With Pointers and Arrays

In this tutorial, we will show you how to effectively debug pointers and arrays in C using the Eclipse IDE.

By 
Erich Styger user avatar
Erich Styger
·
Jul. 12, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
12.3K Views

Join the DZone community and get the full member experience.

Join For Free

In the C programming language, it is good practice to pass values by reference (using a pointer), especially for a large set of data. For example, the following function takes a message  string and pointer to integer data. It is then printed to the console, as shown below:

static void printData(const char *msg, const int *intBuf, size_t bufSize) {
  puts(msg); /* print message */
  for(int i=0; i<bufSize;i++) {
    printf("buf[%i] = %i\n", i, intBuf[i]);
  }
}


I can also use it as below:

static int intArray[] = {0, 1, 2, 3, 4, 5};

printData("int buf Data dump", intArray, sizeof(intArray)/sizeof(intArray[0]));


Then, it prints something like this into the console:

int buf Data dump
buf[0] = 0
buf[1] = 1
buf[2] = 2
buf[3] = 3
buf[4] = 4
buf[5] = 5


Now, so far so good. Readers familiar with the C/C++ programming language know that pointers and arrays are kind of interchangeable — a pointer to an element can always be treated as a pointer to an array of elements. As with the code above, the function printData()receives two pointers. These are actually pointers to arrays.

In Eclipse/CDT, the MCUXpresso IDE 10.2 is based on Eclipse Oxygen, but it is pretty much the same as any other Eclipse version. When debugging the function printData() in Eclipse/CDT, the parameters are displayed as normal pointers. This happens because of what the function has received and/or knows about it.

Image title

Debugging Pointers

Dereferencing the pointer in the Variables view will only show the first element:

Image title

first array element 

But, how can we see the full array in the debugger? For a pointer to a character, the debugger can show the string (or array of char):

Image title

char array pointer

See Eclipse Debugging with Strings and Eclipse Debugging with Strings - Part 2 for a detailed discussion about how to debug string with Eclipse.

Also, for pointers to other data types, Eclipse recognizes that the address matches the intArray  memory object:

Image title

intArray

How can you see the array behind that pointer? For this, there is a context menu to display a pointer as an array:

Image title

Display as Array

Because the size of the array is not defined, I can specify the length of the array to be displayed as:

Image title

Display as Array Dialog Box

And, voilà:

Image title

Array Values

Obviously, it will show 'random' values, if I decide to show more data elements than the array really has defined.

To go back and show the normal pointer again, I can restore the original type:

Image title

Restore Original Type

And, that's it! Happy arraying!

Pointer (computer programming) Eclipse Data structure

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Floyd's Cycle Algorithm for Fraud Detection in Java Systems
  • Sliding Window
  • Tarantool: Speeding Up Development With Rust
  • How to Implement Linked Lists in Go

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!