Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: Something to Remember About Variable and Module Names

Re: Something to Remember About Variable and Module Names 6 years 6 months ago #16417

  • Jon Chandler
  • Jon Chandler's Avatar
  • Offline
  • Moderator
  • Posts: 365
  • Thanks received: 352
I recently came across a slight problem when I was working on a Swordfish module. I had named it TMP513-VM and called the file TMP513-VM.bas. I don't recall exactly what happened when I tried to compile it or the main program calling it. Suffice it to say it was obvious that it didn't compile.

I knew it should have compiled, since I had copied a module called TMP513 which compiled fine and made a couple minor edits.

On a hunch, I renamed the module TMP513_VM and it compiled as expected. The hyphen/dash/negative sign is used for compiler directives, so I correctly thought that could be the problem.

On the Swordfish forum, David confirmed this and added that module names must follow the same rules as variable names. No spaces or hyphens are allowed.

I may have known this at some point but I'm not sure. This may explain some of the occasional errors where things just don't work until a variable name happens to get changed.

This is a good point to file away.

Re: Something to Remember About Variable and Module Names 6 years 6 months ago #12880

  • majenko
  • majenko's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 62
Heh... in general anything with a - is to be avoided. - is subtract, so TMP513-VM is TMP513 minus VM, which unless you have variables called TMP513 and VM, it makes no sense.

Re: Something to Remember About Variable and Module Names 6 years 6 months ago #12881

  • Jon Chandler
  • Jon Chandler's Avatar
  • Offline
  • Moderator
  • Posts: 365
  • Thanks received: 352
Heh... in general anything with a - is to be avoided. - is subtract, so TMP513-VM is TMP513 minus VM, which unless you have variables called TMP513 and VM, it makes no sense.


True if that was a variable but it's a module or include file. It's not obvious that the same conventions would apply.

Re: Something to Remember About Variable and Module Names 6 years 6 months ago #12882

  • majenko
  • majenko's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 62
I don't know about basic, but in c++ a class (module) instance is just a glorified variable, so there can be no distinction.

Re: Something to Remember About Variable and Module Names 6 years 6 months ago #12883

  • bitfogav
  • bitfogav's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Thanks received: 53
It's not obvious that the same conventions would apply.
I agree with Jon its not obvious, and it is worth pointing out which Jon as done.

The SF manual also states pg56
Creating Modules
module identifier
[device = devicename]
[clock = frequency]
{modules}
{declarations}
{statements}
[end]

Identifier – A mandatory module name, which follows the standard identifier
naming conventions

So if we look at the Identifier naming pg2
Identifiers and Reserved Words
The most common use of an identifier is to name constants, variables, aliases,
structures, subroutines and functions. You should try and use descriptive names
for identifiers, as this will make your program easier to follow and debug. A valid
identifier is composed of the following elements] letter {letter | digit | underscore}
In other words: an optional underscore character followed by a single letter of the
alphabet, followed by one or more letters, digits or underscores.
A reserved word has a special meaning for the compiler and cannot be used as an
identifier. A list of reserved words is shown in Appendix 2.
Time to create page: 0.235 seconds