Hello--

I've been writing some code in C++ to test the tffs-lib library, which is written in C. The library provides functions for directly accessing a FAT file system from within a program. Although most modern operating systems have drivers for accessing the FAT filesystem on SD cards, I am working with an embedded Linux system, and I would like to directly access the FAT filesystem using a device node (/dev/mmcblk1p1) to speed up write I/O access.

I am able to build the tffs-lib and statically link it with my test program. My cross-compiler build is based on gcc 4.2.2.

However, I receive the following error when compiling the code. This error mentions an "anonymous struct," which I believe is not legal in C++.

request for member 'fatsz' in 'htffs', which is of non-class type '<anonymous struct>*'	test.cpp test-tffs-lib

Is it possible to use an anonymous struct in C++, even when the anonymous struct is being used within a C library? I tried passing the command-line switch "-features=extensions" to gcc, but (strangely enough) this results in no executable being created. However, after passing this switch, there is no warning generated, and the code compiles cleanly (without the output executable being created.)

Here is the code of my very simple test program in C++. The error occurs on line 32 below.

#include <iostream>
#include <string>

// TFFS library include (for C code)
extern "C" {
#include <tffs.h>
}

void doTest();

int main()
{
	doTest();
return 0;
}

void doTest()
{
	int32_t ret;
	std::string sd_dev = "/dev/mmcblk1p1";
	tffs_handle_t htffs;

	//  mount the filesystem directory
	ret = TFFS_mount((byte*)sd_dev.c_str(), &htffs);
	if(ret != TFFS_OK)
		 exit(1);

	// check the space available on the medium

        // This is the line of code where the error occurs
	uint32_t fatsz = htffs.fatsz;
	std::cout << "fatsz = " << fatsz << std::endl;

	// unmount the filesystem directory
	ret = TFFS_umount(htffs);
	if(ret != TFFS_OK)
		exit(1);
}

> uint32_t fatsz = htffs.fatsz;
Well that's the whole POINT of handles, and that is to be opaque for external users.

It's basically the same as the 'this' pointer if you had a C++ class. It's just a magic token you pass to each "member" function of the public interface so it can distinguish between various instances.

It is no more wise to try and smash your way through an anonymous struct to get at the data behind it, than it is to smash your way through a class to rummage around with the private variables.

Comments
Thank you for pointing this out!

Ah, okay - thanks for pointing that out, Salem! I will have to obtain the size of the FAT disk by some other way.

This question has already been answered. Start a new discussion instead.