Skip to content

Conversation

@marius7600
Copy link

Problem

Variables defined after STRUCT variables were assigned incorrect memory addresses, causing a systematic offset in the exported symbol addresses.

Root Cause

After parsing STRUCT variables, the parser did not align the bit address counter to the next 2-byte boundary before continuing with subsequent variables. This caused variables following STRUCTs to be placed at incorrect memory positions.

Example

  • Before: ix_AutomaticStart got address DB320:0.3 instead of DB320:2.0
Screenshot 2025-07-21 092959
  • After: Correct address DB320:2.0 as expected in STEP 7
grafik

Solution

Added 2-byte alignment (_AlignUp(2 * 8)) at the end of _AddStructVariable() to ensure subsequent variables start at correct memory boundaries, maintaining STEP 7 memory layout compliance.

Testing

  • Verified with multiple DB files
  • Address calculations now match STEP 7 program addresses
  • Last variables in DBs have correct addresses (confirming no systematic offset)

Files Changed

  • src/EnlyzeS7PLib/src/CMc5codeParser.cpp: Added alignment after STRUCT processing

- Add 2-byte alignment after STRUCT variables in _AddStructVariable()
- Prevents subsequent variables from being placed at incorrect addresses
- Fixes issue where variables after STRUCTs were offset by incorrect bit positions
- Ensures proper STEP 7 memory layout compliance

Resolves address calculation errors where variables following STRUCT
definitions were assigned wrong DB addresses (e.g. DB3200:0.3 instead
of DB3200:2.0).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant