LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2010, 04:33 AM   #1
jamesbon
Member
 
Registered: Jun 2010
Posts: 147

Rep: Reputation: 9
How can I use __attribute in my program


I have checked following two pages
http://unixwiz.net/techtips/gnu-c-attributes.html
and this page also
http://gcc.gnu.org/onlinedocs/gcc-4....ttributes.html

In following program I want to use attribute keyword of C and format string as printf
Code:
#include<stdio.h>
int myfunction (int ,int);
int main ()
{
 int a,b,c;
 printf("Enter 2 numbers \n");
 scanf("%d,%d",&a,&b);
 c = myfunction(a,b);
 printf("the result is %d ",c);
 return 0;
}

int myfunction (int a,int b)
{
 int c;
return c=a+b;
}
I am not clear as what modifications should I do in it.

Last edited by jamesbon; 11-22-2010 at 08:38 AM.
 
Old 11-23-2010, 03:16 PM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by jamesbon View Post
In following program I want to use attribute keyword of C and format string as printf
You seem to be starting from the point of wanting to use one of the compiler's features, as opposed to doing the job the right way. The format attribute GCC provides is to sanitise function inputs at compile-time. You don't define any functions that take varadic arguments according to a format string, so a format attribute cannot be used here.


Quote:
Originally Posted by jamesbon View Post
I am not clear as what modifications should I do in it.
Neither am I - possibly this is because you don't need to use GCC's attributes?

Last edited by JohnGraham; 11-23-2010 at 03:19 PM.
 
  


Reply



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
LXer: Can't Program, won't Program? Then Mash the Web with Mozilla's Ubiquity LXer Syndicated Linux News 0 05-01-2010 12:30 PM
open source dvd/cd copy program? burning on the fly program? vieya Linux - Software 3 12-14-2009 09:16 PM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 09:09 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:29 PM.

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