Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - Undefined Read/Write for scratch variable when compiling to C

(you are viewing a thread; or go back to list of threads)

Undefined Read/Write for scratch variable when compiling to C (by Luis E Varona, P.E)
Dear Mr. Westhues

Thanks for the software I think is great! Just to report a bug that repeats itself when compiling to C that is very bothersome.

Definitions Read_I_scratch and Write_I_scratch have to be entered manually each time a new compilation is done.

Also, there are some C compilers that don't initialize Global variabes to 0, do you think is possible to modify LDmicro to do so automatically i.e Static... I_scratch=0;
It is cumbersome to do so each time a modification is done to the ladder program.

Thanks in advance
Luis Varona
Sun Apr 11 2010, 00:11:17
(no subject) (by Jonathan Westhues)
Can you post an example that demonstrates the Read_I_scratch problem?

A C compiler should always initialize static variables to zero, if no other initializer is specified. This is required by the ANSI standard; so any compiler that doesn't do this is broken. Is there really a compiler that correctly handles static int x = 0;, but not static int x;?
Sun Apr 11 2010, 00:26:32
R_I_scratch Problem (by Luis E Varona, P.E)
Jonathan:

Thanks for your prompt response. Attached you will find an example. I am using LDmicro 2.1

Note that I a using a lot of "magical variables" which I take care in the main program as extern's. Once the manual fixes are done, everything works perfect!

As for the Compiler, I am using MikroC Pro, in their manual they specifically state that they deviate from the ansi standard in that it doesn't initialize globals to zero.

I like your software and the mentioned compiler, if you can make them work flawlessly it will become the perfect marriage! ( I can live with the situation, but sometimes becomes a drag)

Regards;

Luis Varona
Sun Apr 11 2010, 12:05:32, download attachment Target Big Display Complete Cystern 18F4520[1].ld
(no subject) (by Jonathan Westhues)
Interesting, there was a terrible problem in the ANSI C target: in LDmicro the bit and integer variables are separate namespaces, but they were getting collapsed down to one. Your problem occurred because internally, there's both a bit named $scratch and an integer named $scratch.

I've fixed that now, by adding a prefix to distinguish bit from integer variables. Note that this will require you to modify all your "magic variable" names in the C code that links against the LDmicro output.

That's weird about the MikroC compiler. But it doesn't seem like it could hurt to generate the "= 0" part, so I modified the target to do that.

I've attached a test version with these changes. Let me know if that works, or if you still see any issues.
Sun Apr 11 2010, 16:05:27, download attachment ldmicro.zip
(no subject) (by Luis E Varona, P.E)
To:Sir Jonathan Westhues

It is incredible how fast you solved the subject issue!. I almost cried when I saw all those =0; already in the code!.

After changing the names of the "magic variables" in the main program + ladder.h to b's and i's the thing works like a charm! and the scratch variable definition is already there. No conflicts from different namespaces anymore.

There are no words to describe how grateful I am for you to take your time and fix this issue, from now on I will call you Sir Jonathan Westhues already up there with Paul Mcarney.

I will let you know if I find any other issues(I doubt so)

Regards;
Luis E Varona
Sun Apr 11 2010, 21:01:41
(no subject) (by BoumPower)
Hi

I'm writing (I stopped a few time for an urgent work) a compiler for LDmicro files.

You will find in attachment a sample of blink.ld output.

It will help me to have some remarks or suggestion to produce easy to use C code.

Best regards
Olivier

PS : and, everybody that will join the project is welcome !
Mon Apr 12 2010, 15:34:02, download attachment test1.c
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):