LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2013, 08:07 AM   #1
loveternity
LQ Newbie
 
Registered: Apr 2013
Distribution: Ubuntu 12.04
Posts: 3

Rep: Reputation: 0
Question A simple Compilation Error


In my program,there is a function like this:
Code:
int show_filetype(const struct stat *restrict nbuf)
{
     //.....
}
When i compile the program, it shows that
"expected ';' , ',' or ')' before 'nbuf'"

But i don't know why.
who can help me....

Last edited by loveternity; 05-11-2013 at 08:17 AM.
 
Old 05-11-2013, 08:25 AM   #2
loveternity
LQ Newbie
 
Registered: Apr 2013
Distribution: Ubuntu 12.04
Posts: 3

Original Poster
Rep: Reputation: 0
The full code:
Code:
//stats_t.c
//
//Testing stat(),fstat(),lstat()
//

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int show_filetype(const struct stat *restrict nbuf);

int main(int argc,char *argv[])
{
	int fd;
	struct stat buf;

	if (argc == 1)
	{
		printf("Usage: a.out <filename/path>\n");
		exit(-1);
	}

	if (stat(argv[1],&buf) < 0)
	{
		char buf[50];
		sprintf(buf,"stat %s error",argv[1]);
		perror(buf);
	}

        //print the infomation of struct stat

	printf ("st_mode = %d\t\t\t",buf.st_mode);
	show_filetype(&buf);
	printf ("st_ino = %ld\n",buf.st_ino);
	printf ("st_dev = %d/%d\n",major(buf.st_dev),minor(buf.st_dev));
	if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode))
	{
		printf (" (%s) st_rdev = %d/%d\n",
				(S_ISCHR(buf.st_mode)) ? "character" : "block",
				major(buf.st_rdev),minor(buf.st_rdev));
	}
	printf ("st_nlink = %d\n",buf.st_nlink);
	printf ("st_uid = %d\n",buf.st_uid);
	printf ("st_gid = %d\n",buf.st_gid);
	printf ("st_size = %ld\n",buf.st_size);
	printf ("st_atime = %ld\n",buf.st_atime);
	printf ("st_mtime = %ld\n",buf.st_mtime);
	printf ("st_ctime = %ld\n",buf.st_ctime);
	printf ("st_blksize = %ld\n",buf.st_blksize);
	printf ("st_blocks = %ld\n",buf.st_blocks);


	exit(0);
}

int show_filetype(const struct stat *restrict nbuf)
{
	
	char * ptr;
	if (S_ISREG(nbuf.st_mode))
		ptr = "regular";
	else if (S_ISDIR(nbuf.st_mode))
		ptr = "directory";
	else if (S_ISCHR(nbuf.st_mode))
		ptr = "character special";
	else if (S_ISBLK(nbuf.st_mode))
		ptr = "block special";
	else if (S_ISFIFO(nbuf.st_mode))
		ptr = "fifo";
	else if (S_ISLNK(nbuf.st_mode))
		ptr = "symbolic link";
	else if (S_ISSOCK(nbuf.st_mode))
		ptr = "socket";
	else
		ptr = "** unknown mode **";
	printf("%s\n",ptr);

	return 0;
}

Last edited by loveternity; 05-11-2013 at 08:26 AM.
 
Old 05-11-2013, 08:26 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,631

Rep: Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265Reputation: 7265
probably this? http://gcc.gnu.org/onlinedocs/gcc/Re...-Pointers.html
 
1 members found this post helpful.
Old 05-11-2013, 08:33 AM   #4
loveternity
LQ Newbie
 
Registered: Apr 2013
Distribution: Ubuntu 12.04
Posts: 3

Original Poster
Rep: Reputation: 0
Wink

Quote:
Originally Posted by pan64 View Post
Thank u!
In GCC the restrict keyword is __restrict__
So i change it like this:
Code:
int show_filetype(const struct stat *__restrict__ nbuf)
it's right!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple error utkarshrawat Programming 6 08-21-2010 09:25 PM
simple error ...... can u help !!!! bhb Linux - Newbie 4 05-20-2010 07:51 AM
perl: simple one line replacement, simple error message! pwd_pwd_omg_pwd Programming 8 11-19-2008 12:53 PM
Simple SH Error - I hope... Micah Programming 5 06-28-2005 10:41 PM
A simple error?? absolute0net Linux - Networking 3 07-08-2003 02:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration