Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7953 Discussions

Using short file names ( 8-dot-3 ) instead of long file names

SergeyKostrov
Valued Contributor II
427 Views

Everybody knows that short file names ( 8-dot-3 ) could be used instead of long file names
with a C/C++ compiler option '/I' or with '#include "..."' directives in a C source file.

Are there any hidden problems with short file names when used on a Windows platform with NTFS
file system? My answer is Yes.

I recently lost almost 2 hours when a project build failed and it was unclear why it happened.
When I finally understood what happened I reproduced a problem.

Let's say there is a C source file with a directive:

...
#include "../Test/ThisIs~1.abc" // Long name is 'ThisIsTest.abc'
...

Do the following steps in a folder 'Test':

Step 1: Create a file 'ThisIsTest.abc'
Step 2: Create a copy 'ThisIsTest.bak.abc' of the file 'ThisIsTest.abc'
Step 3: Rename the file 'ThisIsTest.abc' to 'ThisIsTest.old.abc'
Step 4: Rename the file 'ThisIsTest.bak.abc' to 'ThisIsTest.abc'
Step 5: Delete the file 'ThisIsTest.old.abc'

Result is as follows:

When a C/C++ compiler will try to compile the C source file with a directive

...
#include "../Test/ThisIs~1.abc" // Long name is 'ThisIsTest.abc'
...

it won't find 'ThisIs~1.abc' file because it no longer exists! Instead, there is afile 'ThisIs~2.abc'!

Please take a look at enclosed screenshot from a test computer:


41310-TestFor8dot3File.jpg
0 Kudos
6 Replies
JenniferJ
Moderator
427 Views
Interesting. My guess is that you're developing platform independent code. This is a good tip.

Thanks for sharing.

Jennifer
0 Kudos
SergeyKostrov
Valued Contributor II
427 Views
Just in case I've done the same steps, desribed in my initial post,on aFAT32 file system of a flash drive.
A final shortname was:

'ThisIs~1.abc'

It meansthat NTFS and FAT32 are a little bit "incompatible" when a short file name is assignedto a file.
0 Kudos
andrewop_p_
Beginner
427 Views

Hello

you are welcome

for shorting a long file name, long path tool is the best option, try it.

 

.................

0 Kudos
jimdempseyatthecove
Honored Contributor III
427 Views

The short file name can be considered a hash code concatenated with ~SequenceNumber when the hash code cannot be unique.

Name collisions in the hash code are common. Upon collision, the SequenceNumber is generated such that it is unique for that particular hash code (in that specific directory). This means, depending on sequence of file creation, the ~SequenceNumber appendage may differ from time to time and/or from system to system as you have shown. It is the programmers responsibility to take this into consideration. This is not a fault of the file system.

*** This includes not assuming PROGRA~1 is "Program Files".

Windows could conceivably be (and most likely has been) installed on a DOS system supporting LFN's and having a preexisting folder named "Program Listings" or "Program anything else here".

Jim Dempsey

0 Kudos
SergeyKostrov
Valued Contributor II
427 Views
>>...for shorting a long file name, long path tool is the best option, try it... That problem was detected and solved more than two years ago. Also, it is applicable Only for cases when 16-bit compilers, like Turbo C++ v3.x or OpenWatcom v2.x, are used. Thanks for your interest.
0 Kudos
SergeyKostrov
Valued Contributor II
427 Views
>>...Just in case I've done the same steps, desribed in my initial post,on aFAT32 file >>system of a flash drive. A final shortname was: >> >> 'ThisIs~1.abc' Try to reproduce the problem on a legacy Windows XP Professional operating system.
0 Kudos
Reply