Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detect 32 vs. 64-bit application

138 views
Skip to first unread message

Robert Lipman

unread,
Jul 21, 2011, 12:57:56 PM7/21/11
to
I have an application that I wrap with Tcl Dev Kit on both 32-bit and 64-bit computers. What Tcl code can I put in my program to detect whether it was wrapped as a 32-bit or 64-bit application? There are some differences in what the program does depending on the 32 vs. 64-bit. How can this be detected?

Thanks,

Bob

Alexandre Ferrieux

unread,
Jul 21, 2011, 1:30:20 PM7/21/11
to
On Jul 21, 6:57 pm, Robert Lipman <robert.lip...@nist.gov> wrote:
> I have an application that I wrap with Tcl Dev Kit on both 32-bit and 64-bit computers.  What Tcl code can I put in my program to detect whether it was wrapped as a 32-bit or 64-bit application?  There are some differences in what the program does depending on the 32 vs. 64-bit.  How can this be detected?

Not checked, but what about ::tcl_platform(wordSize|pointerSize) ?

-Alex

George Petasis

unread,
Jul 21, 2011, 1:46:18 PM7/21/11
to

Or the new (8.6?) platform package:

package require platform
platform::generic
> win32-ix86

George

Alexandre Ferrieux

unread,
Jul 21, 2011, 1:52:07 PM7/21/11
to

Doesn't it say 64b as soon as the _processor_ is 64b, regardless of
whether the executable is in 32-bit mode ?
That's what I assume tcl_platform to be smart about... maybe I'm
wrong :)

-Alex

George Petasis

unread,
Jul 21, 2011, 3:24:23 PM7/21/11
to

The example I gave was from ActiveTcl 8.6 beta (32 bit), running on
Windows 7 64 bit, on an 64 bit processor. To my understanding it returns
the architecture Tcl was compiled for.

George

Donal K. Fellows

unread,
Jul 22, 2011, 4:11:43 AM7/22/11
to

What is the purpose of that detection? What decision does it enable?

Donal.

Robert Lipman

unread,
Jul 25, 2011, 9:57:53 AM7/25/11
to
Here's my solution. It checks if anything loaded is a 64-bit version.

set ver32 1
foreach f [info loaded] {if {[string first "x86_64" $f] != -1} {set ver32 0}}

Bob

Robert Lipman

unread,
Jul 25, 2011, 9:56:22 AM7/25/11
to
Thanks for the responses. My application uses ActiveTcl 8.5 and I have no plans (or funding) to switch to 8.6.

The purpose of the detection is to disable some features of the application that are not available in the 64-bit version because some of the packages used by the application, do not have 64-bit versions.

There was also another odd difference between the 32 and 64-bit versions. Sometimes one of the procedures gets called recursively hundreds of times. I had determined on the 32-bit version that there was a limit to the recursion of about 600 times before it would crash with an error about a stack limit and an infinite loop. With the 64-bit version this limit is around 500 times.

Bob

Ralf Fassel

unread,
Jul 25, 2011, 10:24:23 AM7/25/11
to
* Robert Lipman <robert...@nist.gov>

| The purpose of the detection is to disable some features of the
| application that are not available in the 64-bit version because some
| of the packages used by the application, do not have 64-bit versions.

Then why not simply
if {[catch {package require somepackage}]} {
# disable features provided by 'somepackage'
}
?

R'

Zbigniew Diaczyszyn

unread,
Apr 17, 2012, 7:02:26 PM4/17/12
to
For example:

Your Tcl/Tk application has to check if there is a new version for a
download. If Tcl could determine the type of the host system it could
fetch the right version or propose the user to decide if he wants to run
a 32bit version on his 64bit host.

To choose the right C extension for a running Tcl application I am
working with "tcl_platform(machine)" which gives the values "i686" for
32bit or "x86_64" for 64bit systems

alain

unread,
Apr 18, 2012, 4:12:30 AM4/18/12
to
$tcl_platform(machine) to know what's under the bonnet.
Since starkit 8.5.1, $tcl_platform(pointerSize) returns 4 or 8
to know what the application is running actually 32 (machine
i686 or x86_64) vs 64 (x86_64 machine only).
Alain.

Donal K. Fellows

unread,
Apr 18, 2012, 1:06:23 PM4/18/12
to
On 18/04/2012 00:02, Zbigniew Diaczyszyn wrote:
> Your Tcl/Tk application has to check if there is a new version for a
> download. If Tcl could determine the type of the host system it could
> fetch the right version or propose the user to decide if he wants to run
> a 32bit version on his 64bit host.

OK, I'd suggest seeing if the "platform" package is present. If it is,
[platform::identify] will give you the sort of descriptor you need (a
token useful when choosing what native code bundle or executable to
download). The "platform" package is present from Tcl 8.5 onwards, but
you might need to handle aliases as later versions of it are better at
discrimination of what matters.

Donal.

Zbigniew Diaczyszyn

unread,
Apr 19, 2012, 9:22:22 AM4/19/12
to
@Alain
@Donal

Your explanations were helpful. Thanks.


0 new messages